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.

Widgets /

Discuss SilverStripe Widgets.

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

Submenu in Widget


Go to End


5 Posts   3001 Views

Avatar
Iain_vdw

Community Member, 22 Posts

25 November 2009 at 12:26am

Hi there,

I've been trying to make a submenu widget which shows the children of the current page you're on. However, the menu doesn't show.

This code is in my widget template:

	<% if SubNav %>
	Test
		<ul>
		<% control Children %>
			<% control Menu(2) %>
				<li><a href="$Link">$MenuTitle</a></li>
				Test
			<% end_control %>
		<% end_control %>
		</ul>
	<% end_if %>

The widget consists of two options, which can be en- or disabled via the CMS. The enabling and disabling works, that's why i've got the "Test" line in my code. But the menu doesn't show up. I've tried several combinations of control Children, control Menu() and whatnot, but to no avail.

I've got a hunch that tells me the widget doesn't have "access" to the SiteTree and therefor cannot get the children of the current page, is that correct? If yes, how do i alter that?

Thanks in advance!

Avatar
bummzack

Community Member, 904 Posts

25 November 2009 at 1:09am

Get rid of the Menu(2) there. <% control Children %> should be all you need.

Avatar
Iain_vdw

Community Member, 22 Posts

25 November 2009 at 2:26am

Banal, thx for your reply, but that still doesn't work. I've tried every combination of Children and Menu(#), but it doesn't work. I really don't get it why it doesn't...

Avatar
bummzack

Community Member, 904 Posts

25 November 2009 at 2:41am

Yeah. Somehow you'll have to get the Children of the current page... maybe through a helper method on your widget that grabs it using Director::currentPage() ?

Avatar
hive.net.au

Community Member, 40 Posts

25 November 2009 at 3:45am

Edited: 25/11/2009 3:47am

This will most likly not work, but its worth a try, I have not done much with developing widgets.

<% if SubNav %> 
   Test 
      <ul> 
      <% control Parent %> 
         <% control Children %> 
            <li><a href="$Link">$MenuTitle</a></li> 
            Test 
         <% end_control %> 
      <% end_control %> 
      </ul> 
   <% end_if %>