3215 Posts in 848 Topics by 811 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1513 Views |
-
Space character in <% if value = a space %> gives error

23 July 2010 at 1:07am Last edited: 23 July 2010 1:08am
I've been trying to add a class by checking if a value of a certain field has been set to a specified option with the following template code. Only the value that i want to check, contains spaces in the string:
<% control dataFieldByName(FieldName) %>
<% if value = a value with spaces %> class="active"<% end_if %>
<% end_control %>This generates the following error:
Parse error: syntax error, unexpected '}' in <pathname to template on server>Is there a way to use space in comparisons in the template? I've tried "a value with a spaces", <% if value = AValueWithSpaces %>, escaping spaces, etc to no avail.
Any idea how this could be solved, if possible?
-
Re: Space character in <% if value = a space %> gives error

27 July 2010 at 11:44am
Insanely, I don't think this is possible in the template.
You'll need write a function in your php class and call that.
-
Re: Space character in <% if value = a space %> gives error

28 July 2010 at 8:22am
Seriously?
Came here hoping for an answer to this very query and... fail.
Where might I go to find out how to add the function properly? Thanks!
-
Re: Space character in <% if value = a space %> gives error

28 July 2010 at 9:06am Last edited: 28 July 2010 9:08am
All you need to do is create a function in the controller for the page type in question.
Controller:
function getActive() {
if ($this->FieldName == 'a value with spaces') {
return true;
}
}Template:
<% if Active %> class="active"<% end_if %>
Enjoy!
NB: It is important to realise that the templating language is designed to be SIMPLE, this reduces parsing time and enforces a clear separation of controller and view, which is the whole reason we are using a beautiful MVC framework like SilverStripe
-
Re: Space character in <% if value = a space %> gives error

29 July 2010 at 1:58am Last edited: 29 July 2010 1:58am
NB: It is important to realise that the templating language is designed to be SIMPLE, this reduces parsing time and enforces a clear separation of controller and view, which is the whole reason we are using a beautiful MVC framework like SilverStripe
True, but writing custom php functions beats the purpose of an easy templating language as imho the easy templating system shoud allow check for variables with a space. Not everyone knows php as much as some of us do.
-
Re: Space character in <% if value = a space %> gives error

29 July 2010 at 2:59am
I agree with Pigeon on this. Even if it seems the templates should be able to read the string with blankspace in it. I would rather keep the template as clean of the comparison operators as far as possible.
-
Re: Space character in <% if value = a space %> gives error

21 August 2010 at 4:51am
Pigeon, Thanks! You rock!
| 1513 Views | ||
|
Page:
1
|
Go to Top |





