Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Recursive nested menu

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2660 Views
  • pointfiftyae
    Avatar
    Community Member
    2 Posts

    Recursive nested menu Link to this post

    Hi everyone!

    I'm currently working on a project with Silverstripe where the client wants to be able to have a nested menu that works for all menu levels, i.e. it doesn't matter if there are 2 or 9 or n levels, they will all be displayed (the design allows for a fairly good amount of levels). All I've seen on the forums or the current themes are hard-coded menus of a fixed maximum depth.

    I've tried this:

    Nav.ss

    <% control Menu(1) %>
    <!-- here the code for the lists, links etc... -->
    <% include SubNav %>
    <% end_control %>

    SubNav.ss
    <% if Children %>
    <% control Children %>
    <!-- here the code for the lists, links etc... -->
    <% if Children %>
    <% include SubNav %>
    <% end_if %>

    <% end_control %>
    <% end_if %>

    The text in bold is supposed to get the SubNav file to include itself until there are no more children. The problem is that I get an exceeded memory error message. Obviously, the include statements are executed regardless of the ifs, resulting in an endless loop, as stated in this topic: http://silverstripe.com/site-builders-forum/flat/37299

    Does anyone have the same problem, or maybe an idea on how to resolve this? Thank you very much in advance!

  • saimo
    Avatar
    Community Member
    67 Posts

    Re: Recursive nested menu Link to this post

    What you will have to do until the flaw int the templating system is fixed is to do an implementation in php, and put it in Page.php. For example make a new function TreeMenu() and then call that from the template to get a nested tree of the pages. It's a bit ugly, but you could probably use the existing functions for controlling menus, and only use php to make it conditionally recursive.

  • pointfiftyae
    Avatar
    Community Member
    2 Posts

    Re: Recursive nested menu Link to this post

    Hey, thank you for your answer! I guess I will just write 5 or 6 navigation template files for now, and create that PHP function when I have time...

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