0

I'm building a site with Structure, and in my overall navigation, I'd like to vary the show_depth parameter for particular parts of the site.

The following works for the majority of my site's navigation:

{exp:structure:nav css_id="none" css_class="menu" show_level_classes="yes" current_class="active" start_from="/" has_children_class="yes" show_depth="4" exclude="142|144|146|148|150|152"}

However, there are some sections that will have many (hundreds) of entries that are also at the "fourth" level of the hierarchy that I do not want to show in the navigation. For instance: I have a "Press Releases" section, which will have a parent page (called Press Releases), and will list ALL of the site's press releases.

Is there a way to conditionally change the show_depth number for certain parts of the site?

  • Did any of the answers below help you? if so PLEASE mark one as the answer or post your own! – Mark Busnelli Jr Oct 20 '14 at 14:21
0

You can wrap simple conditionals within the structure:nav tag to check the segment first and then set a depth as simple conditionals are parsed before the nav tag:

{exp:structure:nav
    css_id="none"
    css_class="menu"
    show_level_classes="yes"
    current_class="active"
    start_from="/"
    has_children_class="yes"
    {if segment_2 == "press-release"}show_depth="3"{/if}
    {if segment_2 != "press-release"}show_depth="4"{/if}
    exclude="142|144|146|148|150|152"
}
| improve this answer | |
  • Thank you. However, wouldn't this cause unexpected display results when I'm on different pages? For instance: if I'm on the "contact" page (something like example.com/contact-us) where segment_2 was "contact-us", the display depth in the navigation would be incorrect for the "press-release" stack. Does that make sense? We may be misunderstanding one another. – ctrlaltdel Jan 21 '14 at 16:55
  • The conditionals were just an example of how you can control the show_depth parameter based off the segment. So, you might need to add more simple conditionals to get the desired output based off segment – Siebird Jan 21 '14 at 17:06
0

You're much better off using the start_fromparameter for each section of your nav that you would like to display on the front-end, like so:

{exp:structure:nav
        css_id="none"
        css_class="menu
        show_level_classes="yes"
        current_class="active"
        has_children_class="yes"
        show_depth="XXX"
        max_depth="XXX"
        start_from="/press-releases"
    }
    {exp:structure:nav
        css_id="none"
        css_class="menu
        show_level_classes="yes"
        current_class="active"
        has_children_class="yes"
        show_depth="XXX"
        max_depth="XXX"
        start_from="/SECTION-ONE"
    }
    {exp:structure:nav
        css_id="none"
        css_class="menu
        show_level_classes="yes"
        current_class="active"
        has_children_class="yes"
        show_depth="XXX"
        max_depth="XXX"
        start_from="/SECTION-TWO"
    }

Of course for each "SECTION" you'll need to use your own page names to get those to output. This gives a bit more flexibility for how you want your navigation to appear on the site.

I almost forgot that you'll also need to use the max_depth parameter as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.