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   2252 Views

Avatar
ulterior

Community Member, 1 Post

21 January 2009 at 9:20am

Edited: 21/01/2009 9:28am

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

Forum Moderator, 4096 Posts

21 January 2009 at 9:56am

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

Avatar
dio5

Community Member, 501 Posts

21 January 2009 at 9:58am

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.