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.

Widgets

Discuss SilverStripe Widgets.

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

Submenu in Widget


Reply

5 Posts   1806 Views

Avatar
Iain_vdw

25 November 2009 at 12:26am Community Member, 22 Posts

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
banal

25 November 2009 at 1:09am Community Member, 901 Posts

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

Avatar
Iain_vdw

25 November 2009 at 2:26am Community Member, 22 Posts

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
banal

25 November 2009 at 2:41am Community Member, 901 Posts

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

25 November 2009 at 3:45am (Last edited: 25 November 2009 3:47am), Community Member, 40 Posts

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 %>