Empty content object on page in collection unless active

I have a collection built like this:

<?php
return function () {
  return page('artists')->children()->sortBy('sort','asc');
};

…If I loop the collection and echo their titles as in the code below, I get only the slugs, which is very strange…

  <?php if (collection('artists')->isNotEmpty()): ?>
    <?php foreach(collection('artists') as $artist): ?>
      <?= $artist->title()->html() ?>
      ...

…so I tried to dump the collection’s first item and while I get [files] [id] [siblings] etc objects, the content object is empty…

Kirby\Cms\Page Object
(
    [children] =&gt; Kirby\Cms\Pages Object
        (
        )

    [content] =&gt; Kirby\Cms\Content Object
        (
        )

        ...

… if I open one of the pages in the collection, and dump it (from the collection, not from page()), the content object is filled, and the title() shows correctly. But this only happens when I am visiting that particular page, and only for that particular page I am visiting.

Why would the pages in the collection content object be empty unless visiting the particular page. I am lost on that :thinking:

Thank you

Oh… this seems to be related to AJAX… I am trying to figure out in which way

My initial description seems to be accurate. Ajax loading of pages does not modify the behaviour.

If there is an http load of a page in the collection, the title() gets shown correctly for that particular page, and the dump of that page shows a correct [content] object.

In any other case pages in this collection return their slug when asked for title(), and their [content] object is empty on page dump

Crying help from the depths of hell

That is indeed strange and I can’t reproduce it. Could you provide some step by step instructions how to reproduce it in a Starterkit? Also, what Kirby version? Thank you!

@texnixe please check this repo

It is the starterkit with some changes. Only one commit, deleting and adding some files and folders. Mostly page blueprints (artists and artist-item) and collections (mostly artists collection). Plus content.

I already see some weird behaviour on the panel, ‘artists’ page, the ‘artist-item’ titles switch from slug to title in the pages view:

Entering one of these subpages and coming back to ‘artists’ changes the title which is properly displayed:

image

It may be something on the blueprint or a server permissions issue, althoug I supposedly checked the second.

Let me know if you can take a look

It’s the sort by sort blueprint setting in artists.yml causing this. I think you should rename that field to something else, sortfield for example.

Try to avoid naming fields with Kirby’s internal method names. Prevents a lot of issues.

1 Like