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.

Archive /

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

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

silverstripe don't let me add PHP code


Reply


4 Posts   4888 Views

Avatar
ojalà

Community Member, 87 Posts

14 October 2008 at 3:40am

Hi!
I want to add php code in /themes/mytheme/tutorial/Page.ss but I have this error:

Parse error: syntax error, unexpected T_STRING in C:\WINNT\Temp\silverstripe-cacheE--_silverstripe_cms-elisa\.cacheE.._silverstripe_cms.elisa.themes.villevenete.templates.Page.ss on line 25

why?
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..

Avatar
Liam

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.

Avatar
ojalà

Community Member, 87 Posts

14 October 2008 at 5:01am

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

Avatar
Double-A-Ron

Community Member, 604 Posts

17 October 2008 at 12:24am

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

e.g.

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

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

}

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

$myCustomFunction

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: [url]http://doc.silverstripe.com/doku.php?id=tutorials[/url]