Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Displaying Text Based on Enum Value


Go to End


2 Posts   1613 Views

Avatar
DanStephenson

Community Member, 116 Posts

18 October 2011 at 5:00pm

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?

Avatar
martimiz

Forum Moderator, 1391 Posts

18 October 2011 at 11:04pm

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