How to show query in template


Long story short: I’m trying to make a portfolio site.
I’ve made galleries (basically just re-using the kirby3 theme)

Now I want to select some of these albums to show on specific portfolio pages.

In my blueprint I’m using:

    query: site.find("photography").children 
    multiple: true
    info: "{{ page.images.count }} image(s)"
    empty: "No gallery selected"
      cover: true

How do I show these in my template?

I now have

    <?php foreach (page('photography')->children()->listed() as $album): ?>
    <?php if ($cover = $album->cover()): ?><?= $cover->crop(600, 600) ?><?php endif ?>
    <?= $album->title() ?> <span><?= $album->subtitle() ?>
    <?php endforeach ?>

But that is showing ALL the albums.
I just want those selected albums.

Tried to find example code, but it is harder than I thought…
Tx for helping me out. :slight_smile:

You can get all children images like that:

foreach($page->gallery()->toPages()->images() as $image) {}

Or just selected pages:

foreach($page->gallery()->toPages() as $albumPage) {}

The second example @ahmetbora posted gives you the pages selected in your gallery field.

A bit of background explanation:

Your gallery field is a pages field (so basically kind of a multiselect field. It stores the selected pages in yaml format in the content file, like this:


- id/of/page1
- id/of/page2

Kirby provides the toPages() field method to turn those IDs into a pages collection.

The docs are here:, including example how to use in templates.

In your template example, you loop through all the children of the photographypage, ignoring your gallery field.

@texnixe Thanls for this link, somehow missed it totally.
It helped me solve the problem!

for others
<?php $albums = $page->gallery()->toPages(); foreach($albums as $album) ?>
was my missing code