Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » custom <% control Menu(1) %> or <% control Level(1) %>

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: 1553 Views
  • KatB
    Avatar
    Community Member
    94 Posts

    custom <% control Menu(1) %> or <% control Level(1) %> Link to this post

    What order does either Menu(integer) or Level(integer) return in?

    Is it possible to over-ride either Menu(integer) or Level(integer) in your own controller such that you can specify the order you wish?

    Or even <% control children %>?

    I was looking at built-in-page-controls, which contains a link to custom-page-controls which does not yet exist.

  • Sigurd
    Avatar
    Forum Moderator
    628 Posts

    Re: custom <% control Menu(1) %> or <% control Level(1) %> Link to this post

    It returns it in the order you have arranged pages in the CMS (You'll notice you can drag and drop pages around in the CMS, or right-click a 'parent' page and Sort them alphabetically).

    What order are you thinking of re-ordering items by? Date? Alpha? Note that it's best to have the CMS order and public page order the same, otherwise site administrators will become confused.

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: custom <% control Menu(1) %> or <% control Level(1) %> Link to this post

    I think the order is literally determined by the order of the pages in the site-tree in the left pane of the cms...

    (Edit: Sigurd beat me to it ;) )

  • KatB
    Avatar
    Community Member
    94 Posts

    Re: custom <% control Menu(1) %> or <% control Level(1) %> Link to this post

    Possible example:

    Let's say there is a WidgetHolder, with Widgetpages; WidgetHolder can only have WidgetPages as children and each WidgetPage has a price associated with it.

    Let's say that you wanted each WidgetPage to display in price order on the WidgetHolder template, however, because you knew you had so many WidgetPages, you also wanted to create an inline navigation list up to the top, so people didn't have to scroll all the way to the Widget of their choice.

    Wouldn't it be easier to write a custom control to return children in price order?

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: custom <% control Menu(1) %> or <% control Level(1) %> Link to this post

    Instead of Menu() or Level you could have a function like

    function GetWidgetsInPriceOrder() {
    $Widgets = DataObject::get("WidgetPage", "", "Price DESC","", 10);
    return($Widgets) ? $Widgets : false;
    }

    1st argument = what you want to get eg widget page
    2nd argument = the filter (you probably don't need this - Ive set it as "")
    3rd argument = the order which you want it sorted by (Price in DESC or ASC order for example)
    4th = Join (dont worry about that)
    5th = Limit AKA how many you WidgetPages you want to limit to (10)

    Then in the template do <% control GetWidgetsInPriceOrder %> instead of Menu.

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