17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2478 Views |
-
Recursive nested menu

16 June 2008 at 5:26am Last edited: 16 June 2008 5:28am
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!
-
Re: Recursive nested menu

16 June 2008 at 6:41am
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.
-
Re: Recursive nested menu

18 June 2008 at 8:01pm
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...
| 2478 Views | ||
|
Page:
1
|
Go to Top |


