Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Displaying grandchildren pages in alphabetical order

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

Page: 1
Go to End
Author Topic: 736 Views
  • Strandoo
    Avatar
    Community Member
    4 Posts

    Displaying grandchildren pages in alphabetical order Link to this post

    Hi all,

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

    Australia (CityHolder.ss)
    ---Melbourne (City.ss)
    ---Sydney
    Austria
    ---Salzburg
    ---Vienna
    Belgium
    ---Brussels
    ---Bruges
    etc.

    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.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Displaying grandchildren pages in alphabetical order Link to this post

    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 %>

  • Strandoo
    Avatar
    Community Member
    4 Posts

    Re: Displaying grandchildren pages in alphabetical order Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Displaying grandchildren pages in alphabetical order Link to this post

    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.

  • Strandoo
    Avatar
    Community Member
    4 Posts

    Re: Displaying grandchildren pages in alphabetical order Link to this post

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

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