Jump to:

3397 Posts in 978 Topics by 854 members

Template Questions

SilverStripe Forums » Template Questions » Displaying Text Based on Enum Value

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

Page: 1
Go to End
Author Topic: 542 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Displaying Text Based on Enum Value Link to this post

    Hello,

    I am working with the Event Calendar module. Inside my DOM I've added an enum called AgeGroup which allows the user to select three options - Kids Only, Families, Adults Only

    Based on the value the user selects, I want to display a different message. So for example, if the user selects "Kids Only" I want to display the message in the template - "Kids, leave your parents at home"

    I've tried doing this:

    <% if AgeGroup == "Kids Only" %>Kids, leave your parents at home<% end_if %>


    and get this error

    Parse error: syntax error, unexpected '}'

    Can anyone help me correct my syntax?

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: Displaying Text Based on Enum Value Link to this post

    The syntax for an if-control would normally be (with a singe '=' and no quotes):

    <% if AgeGroup = Kids Only %>Kids, leave your parents at home<% end_if %>

    Unfortunately the templating syntax will not allow for spaces within this control, so this will still not work. You might create a function in your Page_Controler, something like:

    function KidsOnly() {
       return ($this->AgeGroup == 'Kids Only');
    }

    then use:

    <% if KidsOnly %>Kids, leave your parents at home<% end_if %>

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