Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Position in menu $pos

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

Page: 1
Go to End
Author Topic: 2471 Views
  • stevejo
    Avatar
    Community Member
    4 Posts

    Position in menu $pos Link to this post

    I am using $pos so I know what position i'm in on the menu. I then reference css using menupos$pos. I use <% if LinkingMode = current %> to find out whether the page should be active or not. What I would like to know is how I can test the position i'm at on the menu say:

    <% Holdmenupos = $pos %>
    <% if Holdmenupos = 1 Then %>
    Do something
    <% else %>
    Do something else
    <% end if %>

    This doesnt however work - in firefox this shows <% Holdmenupos = 1 %> <% Holdmenupos = 2 %> on the page itself .... How would I be able to store and "use" the variable properly in .ss pages?

    Thanks

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Position in menu $pos Link to this post

    Hi stevejo

    If:

    <% if LinkingMode = current %>


    works, i don't see why:

    <% if Pos = 1 %>


    wouldn't...

    Have you tried that?

  • stevejo
    Avatar
    Community Member
    4 Posts

    Re: Position in menu $pos Link to this post

    Hi and thanks for replying. I have tried that however that would actually translate as <% if 1 = 1 %> as $pos holds the position itself.

    Many thanks

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Position in menu $pos Link to this post

    I'm not sure i follow. If you do something like:

    <% control Menu(1) %>
    <% if Pos = 1 %>
    ...
    <% else %>
    ...
    <% end_if %>
    <% end_control %>

    Then for the first menu item it will do the first part of the if statement and the rest will do the else.

    If that isn't the type of thing you want to do, can you elaborate a bit more please?

  • stevejo
    Avatar
    Community Member
    4 Posts

    Re: Position in menu $pos Link to this post

    Sorry I was getting confused with $pos I didnt know that was a "Pos" command.

    This is exactly what I was looking for so many many thanks

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Position in menu $pos Link to this post

    This is also equivalent:

    <% if First %>

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