Title field for homepage is empty when retrieving page using page('home')

I want to create a menu including HomePage.

$items = $site->children();
$items->prepend('home', page('home'));

Then displaying each items on a basic way:

          foreach ($items->listed() as $item):
           ... Some code
            $titre = $item->title();
         <?= $titre->toLink($item->url(),$attr); ?>

         <?php endforeach ?>

No data are present on HTML for HomePage’ link.

This is quite curious because if I append another page, let’s say contact$items->prepend('home', page('contact'));– title data are correctly displayed.

Of course I checked HomePage have a title field!

foreach ($items->listed() as $item):

Is your home folder listed?

The home page is part of $site->children() btw. I assume you are prepending it to have it in first position?


What do you get if you dump




As you can see, the first dump includes the home page, the second doesn’t. So your homepage is not a listed page, i.e. does not have a prepended folder number.

Yes. But I added it manualy…

Yes, but not to the listed pages. Or rather, you add it to all pages, then you filter by listed.

Your step 1:

$items = $site->children();
$items->prepend('home', page('home'));

Your step 2, here you filter by listed:

foreach ($items->listed() as $item):

What you need to do:

$items = $site->children()->listed();
$items->prepend('home', page('home'));
foreach ($items as $item):
1 Like

Ok, it works !