Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17480 Posts in 4474 Topics by 1973 members

Archive

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

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

Page: 1
Go to End
Author Topic: Assigning temporary variables in a template? 658 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
    Moderator
    1823 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!

    658 Views
Page: 1
Go to Top

Currently Online: JoshuaLewis, NickJacobs

Welcome to our latest member: marcusl

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.