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

Best way to hide some menu item


Go to End


7 Posts   2430 Views

Avatar
Possibles

Community Member, 16 Posts

12 January 2012 at 3:52am

Hello

I have this scenario where a website has 2 main section (A and B) those are not part of the menu they are hardcoded (maybe they should be)

Their main menu is common exept for 2 or 3 items that changes or dissapear . So my question is is there a best way to dynamicaly hide some menu item depending on a global variable or something else

If someone could give me a link to some doc or tutorial I could use for that it would be greatly apréciated

Thanks

Avatar
Willr

Forum Moderator, 5523 Posts

14 January 2012 at 4:30pm

You can hide given pages in the CMS by unticking the 'Show In Menus' checkbox under the behaviour tab.

Avatar
Possibles

Community Member, 16 Posts

15 March 2012 at 12:41am

Hello Willr.

I just saw your answer.

I can not do it like that, because the visiblity of my menu item depends on wich section A or B I'm. Those sections are not a menu level in my scenario they are defining a global variable to select the visible and not visible menu item.

Thanks

Avatar
JonoM

Community Member, 130 Posts

15 March 2012 at 3:13am

Edited: 15/03/2012 3:16am

You could define something like this on your Page class

public static $db = array(
	"HideFromMenuA" => "Boolean",
	"HideFromMenuB" => "Boolean"
);

Then for your main menus something like this for Menu A

<ul>
	<% control Menu(1) %>
		<% if HideFromMenuA == 0 %>
			<li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title.HTMLATT}&quot; page">$MenuTitle</a></li>
		<% end_if %>
	<% end_control %>
</ul>

And this for Menu B

<ul>
	<% control Menu(1) %>
		<% if HideFromMenuB == 0 %>
			<li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title.HTMLATT}&quot; page">$MenuTitle</a></li>
		<% end_if %>
	<% end_control %>
</ul>

Avatar
Possibles

Community Member, 16 Posts

15 March 2012 at 4:45am

Thanks a lot

It looks great and simple.

The only problem I have now is how to trigger those bollean values with my 2 hardcoded buttons

Thanks

Avatar
JonoM

Community Member, 130 Posts

15 March 2012 at 5:21am

What do you mean by hardcoded buttons? Can you post your code?

Avatar
Possibles

Community Member, 16 Posts

15 March 2012 at 5:26am

Hello

These are two hardcoded button <a href> buttons in the Page.ss template
But I guess it is not the good solution as they could never relate to the bollean variables.

I will first try to set up your code and see how it goes from there

Thanks for your help

T