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

Whitespace in string comparison


Reply

3 Posts   2167 Views

Avatar
ulterior

21 January 2009 at 9:20am (Last edited: 21 January 2009 9:28am), Community Member, 1 Post

I'm a new user and I've been extending my SS install over the past few days. Everything has been smooth sailing until today when I tried evaluating a string in the template that contained whitespace. If I try..

<% if MenuTitle != "Contact Us" %>

or

<% if MenuTitle != 'Contact Us' %>

or

<% if MenuTitle != {Contact Us} %>

or

(anything, really)

I receive the same error about an unexpected } in Page.ss

I checked the SSViewer.php file and found the regexs that replace the template code and couldn't find any allowance of whitespace in them.

Is there something I'm missing? A special way to escape?

Any help is greatly appreciated, thanks.

-Chris

Avatar
UncleCheese

21 January 2009 at 9:56am 4085 Posts

Not too sure that will work. I always compare URLSegments since they're whitespace free.

Avatar
dio5

21 January 2009 at 9:58am Community Member, 501 Posts

No you're not missing anything.

The template parser is kept very simple.

In your case you could use

<% if InSection(contact-us) %>

or

<% if URLSegment = contact-us %>

to overcome this issue.