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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Displaying grandchildren pages in alphabetical order

Go to End

9 Posts   3873 Views


Community Member, 5 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, 5523 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, 5 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, 5523 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, 5 Posts

3 April 2013 at 11:02pm

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


Community Member, 182 Posts

11 June 2015 at 9:43am

This works if you want to show ALL the grandchildren on one page but what if you want to divide the grandchildren by their parents and still sort them alphabetically? So lists separated by the child page with lists of grandchild pages sorted alphabetically.


Community Member, 419 Posts

12 June 2015 at 2:44am

<% loop $Children.Sort('Title') %>
	<% if Children %>
			<% loop $Children.Sort('Title') %>
			<% end_loop %>
	<% else %>
		<p>No children.</p>
	<% end_if %>
<% end_loop %>


Community Member, 182 Posts

12 June 2015 at 3:01am

Edited: 12/06/2015 4:15am

Many Thanks Pyromanik but I didn't explain well enough what I meant. I need

Children (Listed)
Grandchildren (not shown)
Great Grandchildren Listed (not grouped by their parent in this case the Grandchildren)

If you loop Children twice it groups them. I need to bypass the grouping and take all my great grandchild pages and sort them regardless of their parent. Almost there here:

But now I'm stuck as I'm sorting it by another variable that is not on the Page.php (I think) and getting this error: ORDER BY "ProductReleaseDate" ASC Unknown column 'ProductReleaseDate' in 'field list'

Solved in the end here:

Go to Top