Jump to:

2985 Posts in 761 Topics by 740 members

Template Questions

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

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba

Page: 1
Go to End
Author Topic: 241 Views
  • phawley
    Avatar
    Community Member
    20 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
    4724 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
    20 Posts

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

    Perfect Will...thanks!

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