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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Position in menu $pos


Go to End


6 Posts   3491 Views

Avatar
stevejo

Community Member, 4 Posts

25 August 2009 at 8:10am

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

Avatar
dhensby

Community Member, 253 Posts

25 August 2009 at 9:53am

Hi stevejo

If:

<% if LinkingMode = current %>

works, i don't see why:
<% if Pos = 1 %>

wouldn't...

Have you tried that?

Avatar
stevejo

Community Member, 4 Posts

25 August 2009 at 10:05am

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

Avatar
dhensby

Community Member, 253 Posts

25 August 2009 at 10:43am

Edited: 26/08/2009 10:05am

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?

Avatar
stevejo

Community Member, 4 Posts

26 August 2009 at 8:30am

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 :)

Avatar
Hamish

Community Member, 712 Posts

26 August 2009 at 10:05am

This is also equivalent:

<% if First %>