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.

All other Modules /

Discuss all other Modules here.

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

New Module: Custom Menus


Go to End


56 Posts   14054 Views

Avatar
cumquat

Community Member, 201 Posts

31 May 2011 at 6:55pm

Hi otherjohn,

well i normally copy the menu2 control code from the sidebar.ss include on the blackcandy theme then adapt it from there with regards to how i want it to look, see below.

<ul id="Menu2">
		  	<% control CustomMenu(main-menu) %>
  	    		<% if Children %>
			  	    <li class="$LinkingMode"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span><em>$MenuTitle.XML</em></span></a>
	  	    	<% else %>
		  			<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span><em>$MenuTitle.XML</em></span></a>
				<% end_if %>	  
	  		
	  			<% if LinkOrSection = section %>
	  				<% if Children %>
						<ul class="sub">
							<li>
								<ul >
									<% control Children %>
										<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levelb"><span><em>$MenuTitle.XML</em></span></a></li>
									<% end_control %>
								</ul>
							</li>
						</ul>
			 		 <% end_if %>
				<% end_if %> 
			</li> 
  			<% end_control %>

Hope this helps.

Mick

Avatar
Mo

Community Member, 541 Posts

31 May 2011 at 9:58pm

Edited: 31/05/2011 10:00pm

That is pretty much how I do it, or, if I am just generating a simple nav with no children:

<% if CustomMenu(main-menu) %>
  <ul>
    <% control CustomMenu(main-menu) %>
      <li><a href="$Link" class="$LinkingMode">$MenuTitle</a></li>
    <% end_control %>
  </ul>
<% end_if %>

Avatar
Fouppy

Community Member, 1 Post

17 June 2011 at 3:21am

Hi Mo,

Great module, it does almost exactly what i'm looking for.

Almost, because i can't get it working correctly with a multilingual site. For example, the site i'm working on has two languages, and i can't select pages which aren't in the default locale.

Is there any workaround ?

Cheers

Fouppy

Avatar
Mo

Community Member, 541 Posts

17 June 2011 at 10:14pm

Hi Fouppy,

Unfortunately at the moment multilingual support is limited. I haven't got a huge amount of experience with multilingual sites, so it is tricky coming up with a more supportive version.

Currently it will only show a regional version of the same page across different language versions of a site. So if you have Home, about and contact in your menu, but under a different language only about has content, only about will appear in the menu.

I am interested in adding this functionality, so any feature requests or patches give me a shout on this thread, I will look at implementing them!

Cheers,

Mo

Avatar
Mo

Community Member, 541 Posts

17 June 2011 at 10:17pm

Also, this module has now moved to GitHub. URL is:

https://github.com/mlewis-everley/silverstripe-custommenus

Please feel free to submit patches, I will try to get on them when I have time :).

Mo

Avatar
juneallison

Community Member, 110 Posts

12 July 2011 at 2:41am

Hi Mo - I've installed and set up your module. So far so good! Thank you!

I had a question about adding to the menu. Basically I will be creating one those "chunky" menus that also displays an image and short description with each menu link. When you hover over the link you see the image and description.

1. Is there a way to add and manage these content fields within your module?
2. Do think it would be better to attach these custom fields/data to the actual page (instead of modifying your module)?

Any input you have would be great. Thank you!

Avatar
Mo

Community Member, 541 Posts

13 July 2011 at 12:22am

Hi juneallison,

You can essentially think of the menu object as a filter. It returns a list of pages to the template, based on which pages you added in the CMS.

In your template, anything loaded within the custom_menu() control is actually a page object.

So to do what you want, you would add these items to your page. You could call them something like:

MenuDescription
MenuImage

Then load them inside the loop by using:

$MenuDescription
$MenuImage

Respectively.

Sound ok?

Mo

Avatar
juneallison

Community Member, 110 Posts

13 July 2011 at 2:23am

Ok, got it. So the data will be attached to the page. That makes sense and I see what you are saying about the menu object being a filter. I wasn't thinking about it that way.

Thinking out loud... I mentioned the first option thinking it would be nice if there was a central place to modify these images and descriptions. On the other hand that central location would then have to be updated as pages were added or deleted. Attaching the data to the page seems much more concise in terms of coding.

Thank you for your feedback! I really appreciate it!