Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » Checking variables in .ss pages for a space character only

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 961 Views
  • HallMarc
    Avatar
    Community Member
    3 Posts

    Checking variables in .ss pages for a space character only Link to this post

    I have a variable, $Logo. This is a text string that the user can put in while creating the pages in the admin. However, more than a few times they have inadvertantly filled this with a space character only and so when I call the variable with

    <% if Logo %> (Boolean check) then dothis routine the Boolean value is True. How can I create an if statement to check if the variable is set (equal) to a single space character?
    I have tried
    <% if Logo = " " %>
    and
    <% if Logo = ' ' %>
    both give me a php error.

  • Jardiamj
    Avatar
    Community Member
    17 Posts

    Re: Checking variables in .ss pages for a space character only Link to this post

    Hello HallMarc!,
    I guess you can't do that in your template, but you could do a function in your PageName.php file like this:

    function testLogo(){   
       $result = ($this->Logo == ' ')? True : False;
       return $result;
    }

    And then reference to the function in the template like this:

    <% if testLogo %>
       True
    <% else %>
       False
    <% end_if %>

    I hope it will help. Cheers!

    961 Views
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.