Jump to content

Putting repeater fields from different pages together and sorting the results


JoshoB
 Share

Recommended Posts

I am building a website that serves as a client management system. I have organisations (each a page) and they are parent pages to contacts (i.e. people). Both the organisations and the contacts beneath them have a repeater field, "history_repeater", that is used to store comments in. The repeaters consist of a date/time field ("datetime") and a comment field ("comment"). An organisation page should show the complete history for that organisation, i.e. add the "history_repeater" data from the underlying pages (contacts) to the main "history_repeater" field in the organisation page, and then reverse sort the results by "datetime".

I cannot seem to figure out how to do this in a neat way without taking recourse to building an array. I think it should be doable with a simple selector and sort, but how escapes me at present. Does anyone have a solution for this? Thank you so much in advance.

Link to comment
Share on other sites

Oh, cheers! I think I managed to solve it thanks to that thread.

For posterity/future reference, this is what I wrote in the parent template:

// Populate history_repeater with history from underlying pages, too
foreach($page->children() as $child) {
    $page->history_repeater->add($child->history_repeater);
}
$page->history_repeater = $page->history_repeater->find("sort=-datetime");
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...