Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Assigning temporary variables in a template?

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2742 Views
  • superautomatic
    Avatar
    Community Member
    53 Posts

    Assigning temporary variables in a template? Link to this post

    I have a folder called "clientcases" that includes 4 or five client cases. In the template I list the other clientcases in the sidebar (with a <% control ChildrenOf(clientcases) %> loop ). Now I want to exclude the current case from the list in the sidebar. Normally I'd just assign a temporary CurrentClientCase variable to match against the Title in the loop. But how do I assign a temporary variable like that in SS?

    Example:

    Clientcases
    - Foo
    - Bar
    - Alice
    - Bob

    When viewing the "Foo" page, only Bar, Alice and Bob should be listed in the sidebar.

    So something like this should do it:

    <% control ChildrenOf(clientcases) %>
       <% if Title != CurrentClientCase %>
       ...
       <% end_if %>
    <% end_control %>

    But how do I assign the $Title value to $CurrentClientCase (or another temp variable...)?

    /Jens

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Assigning temporary variables in a template? Link to this post

    You can't assign vars in the template parser. But if you want to hide the current one you could just do <% if LinkOrCurrent = Current %><% else %>// do stuff <% end_if %>

  • superautomatic
    Avatar
    Community Member
    53 Posts

    Re: Assigning temporary variables in a template? Link to this post

    Great, that did the trick. "Current" has to be in lowercase for this to work though. So:

          <% control ChildrenOf(clientcases) %>
             <% if LinkOrCurrent = current %>

             <% else %>
                <h2>$Title</h2>         
             <% end_if %>
          <% end_control %>

    ...does exactly what I want.

    Thanks a lot!

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