Jump to:

22975 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » add php in template.ss

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 2265 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    add php in template.ss Link to this post

    Hi!

    in my template.ss I add php code:
    <?
    echo'aaaaa';
    ?>

    and this is correct. but if i write:
    <?
    print_r($_REQUEST['id']);
    ?>

    I have the following error:

    Parse error: syntax error, unexpected ';' Page.ss on line 9

    why??

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: add php in template.ss Link to this post

    while I think you can use php commands in your ss templates I think you can only do it one at a time within a control, e.g.

    <% sprintf(_t('IMAGE','%2.2s'),$Locale.RFC1766) %>

    so I'd write each php command like this...

    <% print_r($_REQUEST['id']) %>

    but I am no expert.... I think what might be casuing this in fact is that you are tring to access an element in an array and it may be confusing $_REQ..... with a function... but in general I'd avoid php code in an *.ss template - it should go into the controller

    Barry

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: add php in template.ss Link to this post

    There was a comment in another post saying that templates only get one pass, so if you're not dealing with a literal value then it may not work as intended, that could have been relating to something else though.

    However, as Barry has said, templates are not really intended to have code inside them, just control blocks etc. to keep it simple. If you're trying to debug as you develop then write a debug function for your page controller to spit out all the $_REQUEST variables etc.

    hth

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