Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » silverstripe don't let me add PHP code

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

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

Page: 1
Go to End
Author Topic: 3994 Views
  • ojalà
    Avatar
    Community Member
    87 Posts

    silverstripe don't let me add PHP code Link to this post

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

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: silverstripe don't let me add PHP code Link to this post

    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.

  • ojalà
    Avatar
    Community Member
    87 Posts

    Re: silverstripe don't let me add PHP code Link to this post

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

  • Double-A-Ron
    Avatar
    Community Member
    603 Posts

    Re: silverstripe don't let me add PHP code Link to this post

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

    3994 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.