Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Menu Subitems

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1300 Views
  • Terminator4
    Avatar
    Community Member
    81 Posts

    Menu Subitems Link to this post

    Hi,
    I would like to know how to control a menu's subitems and choose to display a specific group in my sitetree. I would like to retrieve only the products on my menu, to a theme Page.ss, as like in the following example:

    -Main
    --Products
    --ProdA
    --ProdB
    --Services
    --ServA
    --ServB

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Menu Subitems Link to this post

    Provided your products are of a different page type you could do something like this:

    <% control Menu(2) %>

    <% if ClassName = ProductPage %>

    <li> $MenuTitle etc.... </li>

    <% end_if %>

    <% end_control %>

  • Terminator4
    Avatar
    Community Member
    81 Posts

    Re: Menu Subitems Link to this post

    Will try that out man. Thanks.

    Is that the only / most efficient way?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Menu Subitems Link to this post

    If you want to ditch Menu(), you'll need to create a custom function in your page class such that:

    function CustomPages($urlsegment) {
    return DataObject::get("SiteTree", "some filter");
    }

    And in your tempalte

    <% control CustomPages(products) %>
    <li><a href="$URL">$Title</a></li>
    <% end_control %>

    Note that you could filter by whatever you want - so you could use a product group and a set of dataobjects, if that is more suitable.

  • Terminator4
    Avatar
    Community Member
    81 Posts

    Re: Menu Subitems Link to this post

    Thats a good idea! Thanks... will try that approach.

  • arthurdent
    Avatar
    Community Member
    153 Posts

    Re: Menu Subitems Link to this post

    Would this approach work in the following instance?

    I have a site with a navigation setup for level 1 and level 2 pages. In some instances The Client wishes to have the list of sub-pages for a section appearing as a plain (bulleted) list within the page content. However in the bulk of the site the sub-pages appear within the navigation.

    My initial thoughts were to use the Menu(2) control, with a condition that the Menu(2) list would only appear if the page was hidden from Navigation. However for obvious reasons this is not going to work so I need a workaround. Does anybody reading this know how to incorporate the aforementioned condition with a 'list children' kind of scenario?

    TIA

  • Martijn
    Avatar
    Community Member
    271 Posts
  • arthurdent
    Avatar
    Community Member
    153 Posts

    Re: Menu Subitems Link to this post

    Hi Martijn - thanks for this! Another helpful thing to know about SilverStripe! Unfortunately it's not quite what I'm looking for - I need to show the subpages of a particular section of the site within that section, while this would give me a list of pages that I selected from throughout the site. From an admin point of view, Client would probably prefer it if this happened automatically!

    You wouldn't happen to know of anything like this, would you?

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