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, Ed, biapar, Willr, Ingo, swaiba

Working with variables in the template

Go to End

3 Posts   629 Views


Community Member, 200 Posts

18 March 2011 at 6:43am

Ok thought this was gonna be an easy one and it maybe although i have spent 5 hours and with my limited knowledge i don't seem to have found the solution.
I have a table on a template page that lists the data from a control, all works ok see below,
<% if Location %>
<table id="Standard">
<th>Grid Ref</th>
<th>Height Restriction</th>
<th>Training Loc.</th>
<% control Location %>
<tr >
<td>$HeightRst </td>
<% end_control %>

<% end_if %>

what i want to do is just show a word if the variable $HeightRst (which is a decimal) is less than 3 the idea being that if the height restriction is less that 3 show a warning word. I have tried putting code in the template page and also in the php page but i don't seem to be able to find the right way of doing it. In my mind it seems easy if $HeightRst < 3 then 'warning' but i just can't seem to get the right code. Any help or pointers much appreciated.



Forum Moderator, 5521 Posts

19 March 2011 at 6:36pm

In 2.* the template engine doesn't support inequalities. You should put this logic in your location model.

function HeightWarning() {
return ($this->HeightRst < 3);

Then you can use <% if HeightWarning %>....


Community Member, 200 Posts

19 March 2011 at 10:11pm

As usual, you come through with the answer, many thanks.