Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Get current page level

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

Page: 1
Go to End
Author Topic: 2616 Views
  • AdamCGray
    Avatar
    Community Member
    4 Posts

    Get current page level Link to this post

    Hello,

    Is there a simple way of getting the level of the current page within the navigation structure? I.e. top of section, sub page, sub sub page etc.

    The reason is that I need the submenu for each section to appear in a different place depending on whether the user is on a top level section page or a sub page. So for example, in the following structure:

    About us
    |- The past
    |- The future
    |- Members

    The 'the past, the future, members' submenu would appear at the *top* on the 'About us' page but on the *bottom* of the 'The Past' page. Realise this is a very confusing description but hope it makes vague sense. Is this possible?

  • 3dgoo
    Avatar
    Community Member
    133 Posts

    Re: Get current page level Link to this post

    In the control of Level(1) or Menu(1) you can check the linking mode:

    <% if LinkingMode = current %>

    // This would be the About us page

    <% else_if LinkingMode = section %>

    // This would be the sub pages

    <% else_if LinkingMode = link%>

    // This would be out of this section completely

    <% end_if %>

  • AdamCGray
    Avatar
    Community Member
    4 Posts

    Re: Get current page level Link to this post

    Thanks for your reply; that tests for the level of the page being linked *to* but not the current (i.e. referring) page, which is what I need to do! Any other thoughts?

  • 3dgoo
    Avatar
    Community Member
    133 Posts

    Re: Get current page level Link to this post

    I can't believe I didn't remember this before:

    <% if Level(1) %>
       // Do what you want
    <% else_if Level(2) %>
       // Do what you want
    <% else %>
       // Do what you want
    <% end_if %>

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