Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

silverstripe don't let me add PHP code

Go to End

4 Posts   5928 Views


Community Member, 87 Posts

14 October 2008 at 3:40am

I want to add php code in /themes/mytheme/tutorial/ but I have this error:

Parse error: syntax error, unexpected T_STRING in C:\WINNT\Temp\silverstripe-cacheE--_silverstripe_cms-elisa\ on line 25

Can I add php code in .ss file? is necessary to include php in tag <?php ... ?> ??I try with this tag and witougth but nothing change..


Community Member, 470 Posts

14 October 2008 at 4:39am

SS follows the MVC approach, which means keeping all different kinds of content separated. You can't add php code in your template, at least not easily. You could do so by using iframes or similar.

PHP code is suppose to go in your page/controller class, and then accessed in the template by using loops and variables.


Community Member, 87 Posts

14 October 2008 at 5:01am

sorry butI post some day agò and I try to solve the problem but I Can't..


Community Member, 607 Posts

17 October 2008 at 12:24am

Put your php code in /mysite/Page.php inside a new function under the Page_Controller.


class Page extends SiteTree {
	static $db = array(
	static $has_one = array(

class Page_Controller extends ContentController {
	function init() {
	// Pull out the currency cookie value and return
	function myCustomFunction() {
        return "Hello World"


Then in your file, simply call the function to output whatever it returns:


You cannot put PHP code into any .ss file. I suggest that you work through the tutorials to get a better idea of how Silverstripe works here: