Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Tree Menu

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

Page: 1 2
Go to End
Author Topic: 3927 Views
  • Jean-Phi
    Avatar
    Community Member
    12 Posts

    Tree Menu Link to this post

    Hi,

    is there an easy way to build a tree menu like this :

    <ul>
    <li><a href="">Section 1</a>
    <ul>
    <li><a href="">Section 1.1</a></li>
    <li><a href="">Section 1.2</a></li>
    </ul>
    </li>
    <li><a href="">Section 2</a></li>
    ............
    </ul>

    from site tree content

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Tree Menu Link to this post

    yes this can be done,

    use the following code

    <ul>
    <% control Menu(1) %>

    <li><a href="$Link">$MenuTitle</a></li>

    <% if Menu(2) %>
    <ul>
    <% control Menu(2) %>

    <li><a href="$Link">$MenuTitle</a></li>
    <% if Children %>
    <ul>
    <% control Children %>

    <li><a href="$Link">$MenuTitle</a></li>

    <% end_control %>
    <ul>
    <% end_if %>

    <% end_control %>

    </ul>

    <% end_if %>

    <% end_control %>
    </ul>

  • Jean-Phi
    Avatar
    Community Member
    12 Posts

    Re: Tree Menu Link to this post

    Thanks, here is my working script :

    <ul id ="navigation">
       <% control Menu(1) %>   
          <li class="$LinkingMode navigation_$iteratorPos"><a href="$Link" title="$Title.XML page" class="$LinkingMode">$MenuTitle.XML</a>
           <% if Children %>
    <ul>
    <% control Children %>
    <li><a href="$Link">$MenuTitle</a></li>
    <% end_control %>
    </ul>
    <% end_if %>
          </li>
       <% end_control %>
    </ul>

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Tree Menu Link to this post

    Good, I see your code only have two levels but mine has three levels ;)

  • Jean-Phi
    Avatar
    Community Member
    12 Posts

    Re: Tree Menu Link to this post

    Yes

    I think there's no way to build a recursive tree with .ss, isn't it?

    while($children){....

  • Antoine
    Avatar
    Community Member
    3 Posts

    Re: Tree Menu Link to this post

    Hi,

    I am trying to do the same and to use ddsmoothmenu.
    I would like to go as deep as the tree is.
    But it seems to be impossible to call a template recursively, isn't it ?

    Menu.ss

    <ul>
    <% control Menu(1) %>
    <li>
    <a href="$Link">$MenuTitle</a>
    <% include _Menu %>
    </li>
    <% end_control %>
    </ul>

    _Menu.ss

    <% if Children %>
    <ul>
    <% control Children %>
    <li>
    <a href="$Link">$MenuTitle</a>
    <% include _Menu %>
    </li>
    <% end_control %>
    </ul>
    <% end_if %>

    <% include _Menu %> in _Menu.ss does not work.
    And what if IK would like to pass an argument like the level ?
    <% include _Menu(level++) %>

    Thanks

  • Antoine
    Avatar
    Community Member
    3 Posts

    Re: Tree Menu Link to this post

    I have released a simple module - ssdropdownmenu - to do that

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Tree Menu Link to this post

    where can i find the code please?

    3927 Views
Page: 1 2
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.