Problems using controllers

Hi, I’m trying to fetch images and some content from subpages this way:

templates: items and item

item Blueprint:

          # sidebar
        width: 1/3
          # a list of files
            type: fields
                label: grid item format
                type: select
                  portrait: portrait
                  landscape: landscape
                  big: big
                label: Illustration
                type:  files
                multiple: false
                layout: cards
                query: page.images
            type: files
            headline: Files

Items controller:


return function ($page) {
  $items = $page->children()->listed()->sortBy('sort');
  return [
    'items' => $items


Items template:

    <?php if($items->count()): ?>

    <?php foreach($items as $item): ?>
    <article class="<?= $item->format() ?> ">
      <?php if($image = $item->coverimage()->toFile()): ?>
        <img src="<?= $image->crop(248, 531)->url(); ?>" alt="Vignette <?= $item->title()->html() ?>" class="showcase-image" width="248" height="531"/>
<?php endif ?>
       <a href="<?php echo $item->url() ?>">Toutes les Infos</a>
<?php endforeach ?>
    <?php endif ?>

Only Title is shown, I can’t get nor image and format. It works correctly with K2.

If I use:

<?php foreach($page->children()->visible() as $item): ?>

in the template all works fine.

What I’am missing ?

Thank you.

What do you get if you do a dump($items)in your items.php template (before the $items->count()if statement)?

Sounds a bit as if the default.php template is used to render the page

Thanks Texnixe, I get this:

Kirby\Cms\Pages Object
    [0] => boats/agantar
    [1] => boats/philia

Ok, two pages, great! Hm, then I don’t see why the single items are not rendered. And it renders nothing from that foreach loop?

Yes title and link render correctly. Only the image and the ‘format’ are not shown

Then maybe there is no image and no format?

Yes they do:

Title: Agantar






Format: landscape



- agantar-yachting-agantar-boat.jpg

What does


give you?

It gives:

I also tried to show these pages on home page with the controller home.php:


return function($page) {
  $items = $site->index()->filterBy('template', 'items')->children()->listed()->sortBy('sort', 'asc'); 
  return compact('items');


But same result

Note: I use the Plainkit to build this theme.

Is the title rendered correctly, i.e. with an uppercase first letter (without any styles or field methods applied)? If none of the content is rendered, it almost seems as if the content file was not readable.

Caching is disabled?

Yes caching is disabled.
No, their is no uppercase in the first letter of title.

I thought so. For some reason, Kirby only reads the folder name, not the content file. Have you created those files via the Panel or with a text editor? Seems they are not readable.

I created them from the panel. Do you think it can have an issue with the plainkit ?
Should I try to replace kirby folder?
Edit: Replace Kirby folder was not useful

You can try that, especially if you’re not using the latest release. But it’s still weird. Have you checked the permissions of those files?

I just replaced with latest starterkit, and same problem.

I use the starterkit in my local server (XAMPP) same as plainkit, and all works perfectly. only difference, I did not try to replace or add image in starterkit from the panel.

Ok, maybe something, I don’t use any yml file for files. maybe that.

Try creating a new album page in the Starterkit, with an image and a headline and check if that renders correctly.

Is caching disabled in your browser?

Edit: Maybe you can send me that plainkit with the failing pages?

Yes it works correctly with a new album photo in starterkit.
Console is always opened with cache disabled (chrome)
I also tried to remove my JS (in case it would causes some troubles)
I’ve quite an empty plainkit with just some css, and debug true in the config. No plugin, nothing :frowning:

Have you tried to recreate those pages? I can’t reproduce this in my environment with a fresh Plainkit.

I just did it, if only 1 item is listed and the other is a draft, the listed one appears. If both are listed, nothing renders…
Same with 3 pages. It works only when just 1 page is listed