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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Customise navigation based on pagetype


Go to End


5 Posts   1395 Views

Avatar
Lime Blast

Community Member, 22 Posts

27 June 2013 at 11:04pm

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?

Avatar
Nobrainer Web

Community Member, 138 Posts

28 June 2013 at 8:48am

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.

Avatar
(deleted)

Community Member, 473 Posts

28 June 2013 at 9:30am

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.

Avatar
Lime Blast

Community Member, 22 Posts

28 June 2013 at 9:12pm

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 :)

Avatar
Nobrainer Web

Community Member, 138 Posts

28 June 2013 at 10:34pm

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.