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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Displaying Text Based on Enum Value

Go to End

2 Posts   1250 Views


Community Member, 116 Posts

18 October 2011 at 5:00pm


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?


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