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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

How do I detect that the page in a menu the current page or a parent of it?


Go to End


2 Posts   1666 Views

Avatar
thepurpleblob

Community Member, 28 Posts

7 December 2009 at 2:32am

Edited: 07/12/2009 2:33am

I am creating a fairly deeply nested menu. I only want to show the 'tree' for the currently selected page. I need to check as the menu is being created that the currently displayed page is either the menu item I am going to display OR the currently displayed page is a child of it.

The first bit is easy - although I'm not sure it's the best way <% if LinkingMode == current %>. However, the second bit I have no idea.

Just to illustrate....

Menu 1
Menu 2
...SubMenu1
...SubMenu2
......SubSubMenu3
...SubMenu3
Menu 3

That is imaging we are displaying page 'SubSubMenu3'. When the top level menu is being generated (control Menu(1) ), how to detect that 'Menu 2' link is a parent of 'SubSubMenu3' and generate the sub menus *only* in that instance?

Any help appreciated!!

Avatar
thepurpleblob

Community Member, 28 Posts

7 December 2009 at 2:46am

Of course, two seconds later solved it <% if LinkOrSection == section %>

BTW... the controls page says one = sign, the docs for the <% if %> says two. Which is right, two seems to work?