user1942505
user1942505

Reputation: 520

How to include php code on a page in octobercms?

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?

Upvotes: 0

Views: 1357

Answers (1)

captiveCorsair
captiveCorsair

Reputation: 374

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 }}

Upvotes: 2

Related Questions