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.

General Questions

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

Checking variables in .ss pages for a space character only


Reply

2 Posts   985 Views

Avatar
HallMarc

17 April 2009 at 7:48am (Last edited: 17 April 2009 7:48am), Community Member, 3 Posts

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.

Avatar
Jardiamj

17 April 2009 at 8:57am Community Member, 17 Posts

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!