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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Whitespace in string comparison


Go to End


3 Posts   3498 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, 4102 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.