hi,
i´ve a problem. i want to use php-code in my theme (page.ss) but, when if i use php i got only a blank site.
but i need php, what can i do? THX!
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
hi,
i´ve a problem. i want to use php-code in my theme (page.ss) but, when if i use php i got only a blank site.
but i need php, what can i do? THX!
As far as I know, you can't. Create a function in your page controller class that returns the result of your php code, then place $FunctionName in the template
You can use StuM's answer if you know what your doing, otherwise you could use an iframe linking to the php script, BUT iframes are the devil, so I'd suggest going with StuM's answer.
hey StuM,
thank you for your answer. in which file i must create my function? ;)
oh no iframes! it´s not a problem for me to create an own function. i only wants to know in which php-file i have to create my own function. thats all ;)
In mysite/code/Page.php, if you've created it. If not, create one with the following:
<?php
class Page extends SiteTree {
static $db = array();
static $has_one = array();
}
class Page_Controller extends ContentController {
function init() {
parent::init();
}
function MyCustomPHPCode()
{
return 'blah blah blah';
}
}
save it as mysite/code/Page.php
then place $MyCustomFunction in your template
I think that's the correct way to achieve it, I'm a SS n00b still and that's how I've been doing it
you may have to run yoursite/db/build?flush=1 to get it working
oh its doesn´t work. i got no output, whats wrong?
Sorry, I put you wrong above, the template variable should be the same as the function name ($MyCustomPHPCode)
I just tried placing php code in the template myself, and it did work(although printed before the html started), so maybe something else is broken
try placing
Director::set_environment_type("dev");
in mysite/_config.php and see if that gives you any hints