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.

Template Questions /

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

CSS dropdown/if-block


Go to End


2 Posts   1833 Views

Avatar
junkbunny

Community Member, 1 Post

11 March 2010 at 9:12am

Hi,

I'm incredibly new to using Silverstripe so forgive me for anything daft I might say.

I've been working on a website here: http://dev.whhf.org.nz - putting a CSS drop-down menu on the navigation. It's working fine but the problem is that the code calls the children of each page that's in the nav. If you hover over the 'news' link, a gigantic drop-down list appears because there are hundreds of news items which are children of the news page.

Is it possible for me to have SS call the children for all the pages EXCEPT 'news' and 'giftshop'?

Here's the code I currently have in Navigation.ss:

<ul id="menu">
 	<% control Menu(1) %>
	  	<% if Last %>
	  		<li class="li-top"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode top sub last" style="margin-left: 0px;">$MenuTitle</a>
			<% if Children %>
				<ul class="leveltwo">
					<% control Children %>
						<li><a href="$Link" class="$LinkingMode" title="$Title">$MenuTitle</a></li>
					<% end_control %>
				</ul>				
			<% end_if %>
			</li>
		<% else %>
  			<li class="li-top"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode top sub">$MenuTitle</a>
  				<% if Children %>
  					<ul class="leveltwo">
  						<% control Children %>
  							<li><a href="$Link" class="$LinkingMode" title="$Title">$MenuTitle</a></li>
  						<% end_control %>
  					</ul>
  				<% end_if %>
  			</li>
		<% end_if %>
   	<% end_control %>
 </ul>

Any help will be greatly appreciated. Please try to explain things to me as simply as possible if you can.. :)

Avatar
Willr

Forum Moderator, 5523 Posts

11 March 2010 at 11:33am

You could add a <% if ShowSubMenu %> around the <% if Children %> then make a function like this in your Page class in mysite/code/Page.php

function ShowSubMenu() {
$ignored = array('news', 'giftshop');

return (!in_array($this->URLSegment, $ignored));
}

In that example I use the URL, but you could use ClassName if they have individual / unique classes. Thats probably safer say if you renamed giftshop later on.