This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

cascer1
cascer1

Hey guys,

I am trying to run a simple PHP script on my page, but I honestly have no idea how to achieve this. I read something about October only being able to execute functions, so I made my code a function that returns a value. (for testing I just made it return "hello, world!"). However I can't seem to get it to display the returned value on the page.

Is there something simple I am missing here?

Daniel81
Daniel81

Hi, on your page in the code tab, you could do something like:

function onStart()
{
    $this->page["myVar"] = "Hello World!";
}

then in your page markup, call the variable myVar like so: {{ this.page.myVar }}

Does that help?

Last updated

Autumn
Daniel81
Daniel81

{{ myVar }} won't work with the above, as the variable is assigned to the page item.

To use it as just {{ myVar }} change $this->page["myVar"] to $this["myVar"]

Last updated

cascer1
cascer1

Thanks!

Is it also possible to show the output of a function that requires variables? I have a function that needs two values as input (funciton getprice($id,$cur)). Would I do something like {{ this.page.myVar(1,eur) }} or wouldn't that work at all?

fededark1702
fededark1702

Hello, I'm trying to create HTML code in a page with PHP but I don't understand how to do

This is my function:

function onStart()
{
    $this["columns"] = function()
    {
        for($i=1; $i<=19; $i++)
            echo "<div class=\"small-1 column bordato\">"+$i+"</div>";
    };
}

And then i call {{ columns }} in the page but i receive an exception message that says "Object of class Closure could not be converted to string" on the {{ columns }} row

Last updated

d.negativa
d.negativa

@fededark1702
in Code section


function onStart()
{
    $this["columns"] = 19; // perhaps this is the number you get from the database
}

in Page (twig section)


{% for column in 0..columns %}
    <div class="small-1 column bordato">{{ column }}</div>
{% endfor %}

Last updated

that0n3guy
joejoezidane
joejoezidane

Go to the "code" tab on an new page, and try this:

function onStart() { echo phpinfo(); }

jesusvaz11281
jesusvaz11281

I undestand a component uses as partial to use AJAX to show data with out generating a page refresh. how do i call different functions once i call one? Besides onStart i have: public function onSelect() which returns data and i handle it inside the partial.

I want to call a different function: public function onGradeQuestion() but i do not figure out how to so it.

I call public function onSelect() this way: <form data-request="{{ SELF }}::onSelect" data-request-update="'{{ SELF }}::quizSelection': '#result'">

I am panning to call onGradeQuestion and fill a new partial with the resulting data <form data-request="{{ SELF }}::onGradeQuestion" data-request-update="'{{ SELF }}::grasdeResult': '#gradeResult'">

It is correct my thinking? i have a hard time figuring out the proper flow of octobercms.

Usually in other languages you create a class with its methods and you call them as you need them. I have a C# background trying octobercms. please help.

emaosv14805
emaosv14805

© 2010-<?php echo date("Y"); ?>

how make it works??

Thx and Regards

Renatio
Renatio

@emaosv14805

If this is in a Twig template than this should work:

© 2010-{{ "now"|date("Y") }}
terrychristian316203
terrychristian316203

how to fetch $this['users'] in Markup page,

This is Code section: function onStart() { $this['users'] = Db::table('users')->get(); //print_r($users); }

baracoaching
baracoaching

how to embed php code to sidebar or page, ex: <?php include('stat.php'); ?>

samiullahsharaf201658040
samiullahsharaf201658040

Hi guys, I am actually stuck where to start the code in the October website. Please tell me where to start the code!!!

Last updated

arif9874158574
arif9874158574

I have controller and method. But how I can use them for show specific page. It is totally shit to find.

1-16 of 16

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.