Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Submenu in Widget

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1797 Views
  • Iain_vdw
    Avatar
    Community Member
    22 Posts

    Submenu in Widget Link to this post

    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!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Submenu in Widget Link to this post

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

  • Iain_vdw
    Avatar
    Community Member
    22 Posts

    Re: Submenu in Widget Link to this post

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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Submenu in Widget Link to this post

    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() ?

  • hive.net.au
    Avatar
    Community Member
    40 Posts

    Re: Submenu in Widget Link to this post

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

    1797 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.