Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Pass a simple string to a template

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: 949 Views
  • Katipo
    Avatar
    Community Member
    7 Posts

    Pass a simple string to a template Link to this post

    How do I pass a simple string value to a template. The examples in the book suggest I should be able to add it as an element to the array passed to the customise function but nothing is being passed to the template.

    For example if I add "MyString"=>"stringvalue" to the array sent to customise and then do <% if MyString == 'stringvalue' %> in my template nothing is happening as MyValue is not passed.

    Any ideas as to what I am doing wrong?

    I am using 2.4

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: Pass a simple string to a template Link to this post

    Test if the value comes up in the template by just calling the variable as so:

    $MyString

    If it comes up, it works.

    For the if statement, I don't think you are allowed to have quotes in there:
    http://doc.silverstripe.org/templates#if_blocks

    So your if statement should be:

    <% if MyString == stringvalue %>

    <% end_if %>

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