Layout breaks because of Error-Page Stylesheet


I have a little problem and are hopping that someone can help me.
From time to time my Layout get’s broken. The cause for this is, that the site loads the error message for unfound sites and attaches the in-document-style of the error message into my site document.

When I look at the code source in the browser i get this:

// my normal site code
// error message with in-document style

Weird is, that the error message is not actually displayed, but It seems like Kirby is looking for something. So maybe it’s because of how I implemented my navigation. This is an example of one navigation button. The layout requires the buttons to be single elements rather than a list.

<?php $item = $pages->find('about');?>
      <a<?php e($item->isOpen(), ' class="active"') ?> href="<?php echo $item->url() ?>"><?php echo $item->title()->html() ?></a>

Has anyone experienced something similar or can see an issue with the way I implemented my navigation elements?
I’m thankfull for any advice!


I must admit that I don’t quite understand your error description. Do you have a link where we can see the behavior?

Appologies if my description wasn’t clear enough. I have a link below. But it’s tricky, because the bug only appears from time to time. So it’s likely that you don’t see it at all.

Normaly all text are aligned to the left. If the texts are centered, then you see the bug. If you then check out the source code in the browser, you will find an error message at the end causing this behavior.

My guess is, that it has something to do with the way I do my navigation. Do you see problem in this? (Example below)

<?php $item = $pages->find('about');?> <a<?php e($item->isOpen(), ' class="active"') ?> href="<?php echo $item->url() ?>"><?php echo $item->title()->html() ?></a>

Is there a better way? Maybe with an array?

I would try:

<?php if ($item = $pages->find('about')) : ?>
<a<?php e($item->isOpen(), ' class="active"') ?> href="<?php echo $item->url() ?>"><?php echo $item->title()->html() ?></a>
<?php else: ?>
<span class="error">Page "about" not found!</span>
<?php endif; ?>

Good luck!

please give us your rendered code from the “error message with in-document style”

And clear the cache of your browser during the development of your site every time you update the website to prevent errors with old stuff…

If the error is caused by Kirby not finding the page, then @anon77445132’s suggestion is certainly a good way to prevent that error. That way, you make sure that the page exists before trying to call a method on it. It would make sense to repeat that for every page.

Like you anticipated, I could not reproduce the issue. Maybe it is caused during upload of a new website version when not all pages were transferred?

Edit: if it happens again, check your php error logs. Maybe you can get some more information regarding the error from there.

1 Like

Thanks everyone for your help! I will try @anon77445132’s suggestions, this makes sense.
The source code from the error looks like this: (It appears right under my regular code)

<!DOCTYPE html>
<html lang="en">

    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
      padding: 10%;
      text-align: center;
      line-height: 1.5em;
    a {
      color: inherit;
    a:focus {
      color: #000;
    p {
      max-width: 30em;
      margin: 0 auto;
    .notice {
      font-weight: bold;
    .admin-advice {
      font-size: .8em;      
      font-style: italic;
      color: #999;
      padding-top: 3rem;

  <p class="notice">
    This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible.
  <p class="admin-advice">
    Advice for developers and administrators:<br> 
    Enable <a href="">debug mode</a> to get further information about the error.

It seems like the error only appears while developing local (with MAMP).
I also did not see the error while the page is on the web, so maybe I can look over it?

Thanks again for you help & time!

When developing, you should turn on debugging in your config.php

c::set('debug', true);

to get useful error messages.

It really seems like it was an local problem caused by MAMP, the website is now online & the bug never appeared again. I still implemented @anon77445132’s advice just to be safe.

Thanks everyone for your help!