Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » Working with variables in the template

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: 472 Views
  • cumquat
    Avatar
    Community Member
    191 Posts

    Working with variables in the template Link to this post

    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">
                   <thead>
                      <tr>
                         <th>Name</th>
                         <th>Grid Ref</th>
                         <th>Postcode</th>
                         <th>Height Restriction</th>
                         <th>Training Loc.</th>
                      </tr>
                   </thead>
                   <% control Location %>
                      <tbody>
                      <tr >
                         <td>$Name</a></td>
                         <td>$GridRef</td>
                         <td>$Postcode</td>
                         <td>$HeightRst </td>
                         <td>$Training</td>
                      </tr>
                      </tbody>
                   <% end_control %>
                   
             </table>
             <% 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.

    Mick

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Working with variables in the template Link to this post

    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 %>....

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Working with variables in the template Link to this post

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

    Mick

    472 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.