Jump to:

3443 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Using Customized Children Loop within Children Loop

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

Page: 1
Go to End
Author Topic: 1190 Views
  • phawley
    Avatar
    Community Member
    21 Posts

    Using Customized Children Loop within Children Loop Link to this post

    I'm trying to sort a list of Appearances within each month, and I have the customized Children control loop working for this in the month template, but in the Year template, first the Children control loop is called and then the customized Children control loop is called, and it returns nothing. The template currently works using standard Children control loops, though:

    in Page.php:

    public function SortedAppearances(){
    // $children will be a DataObjectSet
    $children = $this->Children();

    if( !$children )
    return null; // no children, nothing to work with

    $children->sort('AppearanceDate');

    // return sorted set
    return $children;
    }

    in template:

    <% control Children %>
    ...
    <% if SortedAppearances %>
    <% control SortedAppearances %>
    ...
    <% end_control %>
    <% end_if %>
    ...
    <% end_control %>

    Thanks in advance for any help.
    Patrick

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Using Customized Children Loop within Children Loop Link to this post

    SortedAppearances() needs to be in your Page model, not the controller.

  • phawley
    Avatar
    Community Member
    21 Posts

    Re: Using Customized Children Loop within Children Loop Link to this post

    Perfect Will...thanks!

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