How to create collection from pages with multiple templates

Hello, I have two questions for what I aim to do. I have an Actual page that shows a list events in the future. Those events comes from a panel field pages (like featured).

  • My first trouble: Thoses featured events come from different template page. From a page lecon’s children and the others events comes from the contenucours page’s children offre’s children. I don’t know how to make a collection with two differents kind of page and depth of children. I did not find the reference in the kirby guide. Can you help me to understand how to make collection of those pages?
  • My second trouble, I manage, at least, to make a collection for the events coming from the contenucours but then with this collection I failed to link back the featured events to the original page.

Thank you in advance for your help. I hope my question makes sense. I try to do my best to make it work, but my ability and understanding is still lacking some pieces…


<?php
  $printedTitle = false;
  $actualités =  $data->actual()->toPages()->children();
  $cours =  $actualités->children()
?>

  <?php if(!$printedTitle){?>
  <h3><?= $data->title() ?></h3>
  <?= h($data->text()->kt(), true) ?>

  <article class=" paragraphe separateur">
    <?php foreach($actualités as $actualité): ?>
      <?php if(!$printedTitle){?>
      <?php foreach($cours as $cour): ?>
      <?php
      $events =  $cour->calendrier()->toStructure()->filterBy('date', '>=', date('Y-m-d'));
      foreach($events as $event):
      ?>
        <b><?= $event->date()->toDate('%A %e %B') ?></b><br>
        <b><a href="<?= $actualité->parent() ?> "><?= $cour->title() ?></a></b>
        <p>(<?= $actualité->parent()->title() ?>)</p>
      <?php endforeach ?>
      <?php endforeach ?>
    <?php
      $printedTitle = true;
    }
    ?>
    <?php endforeach ?>
  </article>

<?php
  $printedTitle = true;
}
?>

Do you mean for the query in the Panel or in your template?

You can merge/add collections to other collections like this:

$lecons = page(‘lecons’)->children()->listed()->filterBy(‘template’, ‘in’, [‘template-a’, ‘template-b’]);
$offres = page(‘contenucours’)->grandChildren()->listed()->filterBy(‘template’, ‘in’, [‘template-a’, ‘template-b’]);
$all = $lecons->add($offres);


The second question I don't quite understand. Does the code snippet refer to question 1 or 2?

Thank you for your answer.

The pages with actual events are selected from the panel pages field and called in the actuality page with$actualités = $data->actual()->toPages()->children();
I don’t understand how you move from toPages to $all
Can you help me a little more with this? Thanx

If I understand correctly, these events are stored in a pages field. But then you get the collection by calling toPages() on the field without having to do anything else. Forgive me when I don’t really understand the problem.