This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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?
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
{{ 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
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?
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
@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
Go to the "code" tab on an new page, and try this:
function onStart() { echo phpinfo(); }
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
If this is in a Twig template than this should work:
© 2010-{{ "now"|date("Y") }}
how to fetch $this['users'] in Markup page,
This is Code section: function onStart() { $this['users'] = Db::table('users')->get(); //print_r($users); }
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
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