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.

Template Questions /

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

Displaying grandchildren pages in alphabetical order

Go to End

5 Posts   1273 Views


Community Member, 4 Posts

26 March 2013 at 1:03am

Hi all,

I'm trying to display links to 'nephew' pages; i.e. sibling pages' children. The structure is like this:

Australia (
---Melbourne (

When on any page, I'd like to display a list of countries and a list of cities (in a select menu) for navigation between all pages. The countries aren't a problem (using <% loop Menu(2) %>) but looping menu(3) just gives me the few sub-pages of a given country.

I've come close by using a sibling function found here. This gives me a list of links, but they're listed by country, so it's a bit random looking:
- Melbourne
- Sydney
- Salzburg
- Vienna
- Brussels
- Bruges

Is there a way to output the list alphabetically? I'm a noob, so you may need to go in to some detail! Thanks in advance.


Forum Moderator, 5521 Posts

26 March 2013 at 8:03pm

While inside your Loop Menu(2) use <% loop Children %> to get the children of the 2nd level. If you want to sort you can use .Sort in templates - <% loop Children.Sort(Title) %>..<% end_loop %>


Community Member, 4 Posts

3 April 2013 at 1:43am

Hi Willr. Thanks for your quick reply. I've tried your suggestion but it's still not doing what I want. Using .Sort(Title) does sort the children, but only within the parent. So, while my cities are sorted within their country, I really want them sorted without reference to their country:

Current: ...Dublin, Killarney, Shannon, Florence, Milan, Rome Venice, Kyoto, Tokyo ...
What I want: ...Dublin, Florence, Killarney, Kyoto, Milan, Rome, Shannon, Tokyo, Venice, ...

The parent countries aren't listed, so I'd like to have all the cities listed as one long alphabetised list.

Any suggestions?


Forum Moderator, 5521 Posts

3 April 2013 at 6:34pm

Then don't use nested controls, create a new function to return your sorted list

function getCities() {
return DataObject::get("City", "", "Title ASC");

Assuming you have a pagetype for 'City', if not, then you can use the 2nd parameter for doing a SQL 'where' query.


Community Member, 4 Posts

3 April 2013 at 11:02pm

Thanks! That worked nicely. I think this is beginning to make sense to me now!