How To Include Php Code On A Page In Octobercms?

- 1 answer

I want to run a simple php script on a page in Octobercms. I tried that:

<?php echo 123; phpinfo(); ?>

and that:

{% echo 123; phpinfo(); %}

didn't work. How to include a script on a page?



October's CMS pages are only able to execute functions. So for your above example, you need to go to the 'Code' tab and in there write:

function onStart() { echo 123; echo phpinfo(); }

Alternatively, if you are wanting to pass a value, like "123", you can set a variable in the onStart() function and then just call that variable on the page. Like this:

function onStart() { 
    $this["myVar"] = "123";

And then where you want that variable on the CMS page, you write:

{{ myVar }}