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.

Template Questions

How to handle space in if string?


Reply

6 Posts   2122 Views

Avatar
3 midgets In a man suit

14 October 2009 at 4:14am Community Member, 13 Posts

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

14 October 2009 at 4:27am Community Member, 501 Posts

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

14 October 2009 at 4:31am Community Member, 283 Posts

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

Avatar
3 midgets In a man suit

14 October 2009 at 6:48am Community Member, 13 Posts

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

Avatar
dalesaurus

14 October 2009 at 6:56am Community Member, 283 Posts

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

15 October 2009 at 3:02am (Last edited: 15 October 2009 3:08am), Community Member, 528 Posts

Have you tried?

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

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

Otherwise use the URL segment