Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » How do I detect that the page in a menu the current page or a parent of it?

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

Page: 1
Go to End
Author Topic: 1306 Views
  • thepurpleblob
    Avatar
    Community Member
    28 Posts

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

    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!!

  • thepurpleblob
    Avatar
    Community Member
    28 Posts

    Re: How do I detect that the page in a menu the current page or a parent of it? Link to this post

    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?

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