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

How to handle space in if string?


Go to End


6 Posts   2970 Views

Avatar
3 midgets In a man suit

Community Member, 13 Posts

14 October 2009 at 4:14am

Here is the basic situation:

I am trying to figure out how to use a value that has a space in it for an if statement

example:

<% if ProductGroup = Branson Shows %>
<% end_if %>

if the value has no space it works fine i.e.

<% if ProductGroup = Hotels %>
<% end_if %>

but I have a few key values that have spaces in between them

any help would be appreciated

Avatar
dio5

Community Member, 501 Posts

14 October 2009 at 4:27am

If I'm correct, in the latest versions you can use quotes "" and ==, but I don't think spaces are allowed (yet). (Correct me if I'm wrong someone)

An option is to work around it in the controller, where you could iterate over it and add a hyphen or something to it.

Avatar
dalesaurus

Community Member, 283 Posts

14 October 2009 at 4:31am

If you delimit the space with a \ does that work?

Avatar
3 midgets In a man suit

Community Member, 13 Posts

14 October 2009 at 6:48am

I've tried the / and hyphen to delimit the space with no luck.

Avatar
dalesaurus

Community Member, 283 Posts

14 October 2009 at 6:56am

I've confirmed that you can't currently use spaces in template comparisons, delimited or otherwise (for 2.3.3).

They generate template code like this

if($item->XML_val("Pos",null,true) == "24") {  ;

Any spaces, including delimited will produce static text

$val .= <<<SSVIEWER
 <% Pos == "2 4" %>

You can try to modify your names or just group your output differently. Sorry in advanced, I know this is a pretty frustrating limitation in Template Control blocks. I've worked around it before with a control that had a switch/case in it to return a boolean.

Avatar
zenmonkey

Community Member, 545 Posts

15 October 2009 at 3:02am

Edited: 15/10/2009 3:08am

Have you tried?

<% if ProductGroup = BransonShows %>
<% end_if %>

Just removing has worked for me in other controls/if statements

Otherwise use the URL segment