Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Whitespace in string comparison

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

Page: 1
Go to End
Author Topic: 2153 Views
  • ulterior
    Community Member
    1 Post

    Whitespace in string comparison Link to this 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" %>


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


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


    (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.


  • UncleCheese
    4085 Posts

    Re: Whitespace in string comparison Link to this post

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

  • dio5
    Community Member
    501 Posts

    Re: Whitespace in string comparison Link to this post

    No you're not missing anything.

    The template parser is kept very simple.

    In your case you could use

    <% if InSection(contact-us) %>


    <% if URLSegment = contact-us %>

    to overcome this issue.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.