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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Using Customized Children Loop within Children Loop


Go to End


3 Posts   3107 Views

Avatar
phawley

Community Member, 21 Posts

2 September 2011 at 3:30pm

Edited: 02/09/2011 3:31pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

2 September 2011 at 8:08pm

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

Avatar
phawley

Community Member, 21 Posts

3 September 2011 at 1:43am

Perfect Will...thanks!