Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Customise navigation based on pagetype

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 306 Views
  • Lime Blast
    Avatar
    Community Member
    22 Posts

    Customise navigation based on pagetype Link to this post

    I've done a search of the forums for an answer to this, and found a couple of answers that look like they should work, but so far I've not had any joy with this issue.

    Long story short, My site is split into several different sections (listed as the main navigation across the top of the page). Within any one section, I want the side navigation to show the 2nd and 3rd levels of links within that section.

    So far so good, this is working just fine thanks to the following code:

    https://gist.github.com/LimeBlast/b120452040932780ee17

    The issue I'm having is that one of the sections on the site has a hell of a lot of level 2 and level 3 links, so when within that section, I only want the level 2 links to display.

    I figured that seeing as this section is going to be using custom page types, I would be able to test for the page type, and disable the 3rd level from displaying, i.e.:

    sidebarMenu.ss

    <% if $ClassName = "CourseBase" %>

       // don't show anything

    <% else %>

       // display 3rd level links

    <% end_if %>

    (and a couple of variations of this) But it just isn't working.

    Can anyone help me out?

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: Customise navigation based on pagetype Link to this post

    What version are you on?
    If SS3 i think you need to do "=="
    <% if $ClassName == "CourseBase" %>

    Remember ?flush=all other than that i don't know.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Customise navigation based on pagetype Link to this post

    Is CourseBase the classname of the level 1 or level 2 class? If it's the level 1 class, then use <% if $Parent.ClassName = 'CourseBase' %>. If it could also be a subclass of CourseBase, then use <% if $is_a('CourseBase') %> or <% if $Parent.is_a('CourseBase') %>.

    You can also put in $ClassName/$Parent.ClassName outside of the if to make sure it's what you expect. Remember, with the equality check, case matters.

    Both one and two equal signs are fine, and you only need to flush when adding new templates.

  • Lime Blast
    Avatar
    Community Member
    22 Posts

    Re: Customise navigation based on pagetype Link to this post

    I've managed to fix it. I was checking for the wrong thing as I was a little confused by the way lemonstand's templating works, but I'm now checking for the correct class name, and it's working as intended

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: Customise navigation based on pagetype Link to this post

    Thank you simon_w, i just thought you needed to have duoble == sign in ss3, i guess it is recommended, but not a must.
    When changing included templates, i very often have to flush to see changes.

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