Custom home page breaks children

Hi!

Since setting a custom home page with

return [  
'home' => 'project/catalog',
  ];

in my config.php, the children of the catalog page break and I get a 404 if I try to visit them(edit). If I comment out the line in config.php the children work normally.

Thank you,
Einar

There is no such thing as the site template, only a site blueprint. Are you referring to the panel or the frontend? Please describe the issue in more detail, thanks!

My mistake, i mean the “default.php” template. I see now that they are error pages, I was confused because don’t have the title showing anywhere on the page.

Which template does the catalog page use?

Does the page actually exist? Is caching enabled or is the home definition the only content in your config.php file?

Can you explain what you mean by “the children break”?

In theory, there is an infinity of ways that something (“the children”) may not match your expectations (“break”), so in order to understand your problem we need to know what the something is exactly and what your expectations were.

Some possibilities, from the top of my mind:

  • Do you mean that, in PHP templates, if you do page('project/catalog')->children() or ($page->children() when rendering the home page), you get an empty collection, despite that page actually having children?

  • Do you mean that in the Panel, you’re not seeing a list of child pages for that home page? (If so, what is the URL of that panel page where you’re not seeing children listed?)

  • Do you mean that when you attempt to visit any child page of project/catalog, maybe at an URL like /project/catalog/some-page, you get a 404?

  • Or anything else?

@fvsch,

The third option, when I attempt to visit /project/catalog/some-page i get a 404.

@texnixe the “catalog” page uses the home template which looks like this

title: Catalog

columns:

sections:
      pages:
        type: pages
        sortBy: date desc
        template: 
          - nummer
          - post


files: true

options: 
  template: true
  status: true

I don’t know what you mean by is caching enabled in the config so maybe that’s where I went wrong.

Well, that is actually the blueprint, I’d like to have see the php template.

And it would be helpful to see your complete config.php file

The children should actually be reachable under /project/catalog/some-page unless there is something preventing it, like a route, for example.

My bad, not my day today.

The template is super simple:

<?php snippet('header') ?>

<?php snippet('projects', [
    'projects' => $page->children(),

]) ?>

<?php snippet('footer') ?>

Here is my full config file:

<?php

return [
    'debug'  => true,
    'locale'       => 'sv_SE.utf-8',
    'date'  => [
      'handler' => 'intl'
    ],
    'panel' => [
      'css' => 'assets/css/panel.css'
    ],
    
      'home' => 'project/catalog',
      
  ];


Edit: could this somehow be related to me using PHP built in server?

Edit: translated page names to english for consistency

Just checked with the starter kit, and Kirby does not seem to have any logic that would prevent rendering children of the home page, by default.

With the starter content reorganized slightly as:

content/
  photography/
    trees/
      album.txt
      landscape/
        album.txt

If I set 'home' => 'photography/trees' in the config:

  • The / URL path shows the “Trees” album page.
  • The /photography/trees URL path redirects to / (showing the “Trees” album page).
  • The /photography/trees/landscape URL path shows the “Landscape” album page.

So if this is not working for you, chances are you have some faulty logic in a template, controller or custom route. Maybe try pinpointing what is interfering with normal routing by commenting out code systematically?

Edit: I tested with the PHP built-in server, using the composer start command, which is:

$ php -S localhost:8000 kirby/router.php

(If you’re using the PHP built-in server for testing, make sure you are using kirby/router.php as the entry point handling requests.)

Yes, I saw that it worked in the starter kit too.

Isn’t it very strange though? That the children show up as they should before I add the line in config? What’s more is that in the catalog page (the one set as home) the thumbnails of the children load as they should even when their pages are missing. Any ideas for workarounds or further troubleshooting?

I think I figured it out!

Clicking on the links generated by my project loop gives me:

/catalog/child1 which is an error 404

if I manually type in project/catalog/child1 I see the page as it should be.

the links in the foreach loop are generated like so

<?php foreach ($projects->sortBy('date', 'desc') as $project): ?>
  <li>
        <a href="<?= $project->url() ?>">

where projects is defined like:

<?php snippet('projects', [
    'projects' => $page->children(),


]) ?>

How can I generate the correct urls?

This should work:

<a href="<?= url($project->uri()) ?>

Looks like setting the catalog as home affects the url generation

Thank you so much! That did it