Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.


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

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

custom <% control Menu(1) %> or <% control Level(1) %>


5 Posts   1565 Views


13 February 2008 at 12:42pm Community Member, 94 Posts

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 [url=]built-in-page-controls[/url], which contains a link to [url=]custom-page-controls[/url] which does not yet exist.


13 February 2008 at 2:31pm Forum Moderator, 628 Posts

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.


13 February 2008 at 3:12pm (Last edited: 13 February 2008 3:13pm), Community Member, 167 Posts

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 ;) )


13 February 2008 at 4:15pm Community Member, 94 Posts

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?


13 February 2008 at 9:36pm Forum Moderator, 5511 Posts

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.