Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » 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: 1156 Views
  • freshnode
    Avatar
    Community Member
    2 Posts

    PHP Code Link to this post

    Can PHP code be used in the template files AND/OR the "content" section of pages?

    Thanks!

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: PHP Code Link to this post

    Hi Freshnode,

    No, PHP code cannot be using in ss template files at all. This, (in a way) forcers developers to adhere to the MVC way of doing things, so that templates are used only for what they are there for - presentation.

    Any PHP logic you require needs to go into your page controllers. You can create a custom function in your controller like so:

    function myFunction()
    {
    // Any custom logic

    return 'This is my custom text';
    }

    Then all you need to do in your tempalte ss file is call that function like so:

    <div>
    $myFunction
    </div>

    Note that you don't need the divs.

    Hope that helps. Please checkout the silverstripe tutorials for more:
    http://doc.silverstripe.com/doku.php?id=tutorials

    Aaron

  • freshnode
    Avatar
    Community Member
    2 Posts

    Re: PHP Code Link to this post

    Where do you or how do you create page controllers?

    Thanks

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: PHP Code Link to this post

    In the files in /mysite/code/ directory. This is where the code for your page types are setup.

    I'd suggest reading the tutorials like he linked, as it gives a good start.

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