Sorting a collection by dates within range of records
  • Hello,

    First question on forum:

    I am trying to list a number of records, sorted and grouped by their "start_date" and within the range of their dates.

    Essentially I am looking for something like a combination of <v:date_selection> and <v:collection>. Maybe I am overlooking some incredibly obvious way to do this, but could someone give me a pointer?

    A <v:date_collection> perhaps. This would be very helpful in rendering calendars and events lists.

    I am looking for HTML close to the below. In the meantime, do I need to loop through each day with PHP and use the <v:collection> to pull the records for that date?

    <dt>Thursday 19 April</dt>
    <dd>event 1</dd>
    <dd>event 2</dd>
    <dd>event 3</dd>

    <dt>Friday 20 April</dt>
    <dd>event 4</dd>
    <dd>event 5</dd>

  • 2 Answers sorted by
  • I would do something like this:

    <v:collection path="events">
    $date = strftime("<dt>%A %d %B</dt>", (string)$context->start_date);
    if ($date != $old_date) {
    $old_date = $date;
    return $date;
    return '';

  • Perfect,

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion