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.

General Questions /

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

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

Checking variables in .ss pages for a space character only


Go to End


2 Posts   1888 Views

Avatar
HallMarc

Community Member, 3 Posts

17 April 2009 at 7:48am

Edited: 17/04/2009 7:48am

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

Community Member, 17 Posts

17 April 2009 at 8:57am

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!