Kirby Layout Id is a number


i need some help with layout setting. The id is displayed as a long number.
My home.yml has this code:
type: text
width: 1/2
type: text
width: 1/2
label: Background image
type: files

When i write something like “home-intro” in the id field it is not displayed. Instead i get a long number. I use this code to render the layout:

  <?php foreach ($page->layout()->toLayouts() as $layout): ?>

  <section class="grid" id="<?= $layout->id() ?>">

    <?php foreach ($layout->columns() as $column): ?>

    <div class="column" style="--span:<?= $column->span() ?>">

      <div class="blocks">

        <?= $column->blocks() ?>



    <?php endforeach ?>


  <?php endforeach ?>


The field for css classes are working if i change id to class. When i do a vardump i can find the id under attr. What i’m doing wrong?

The layout id is not what you want. You can get the layout settings via the $layout->attrs() method.

echo $layout->attrs()->id();
1 Like

Thanks! That fixes the problem. I just followed the documention on:

But the documention says:
<section class="grid" id="<?= $layout->id() ?>">
Did the documentation need an update to your solution:
<section class="grid" id="<?= $layout->attrs()->id() ?>">

The next thing for me would be to update the code to check if the id field is empty or not. With the provided solution i get this for the block under the first block:
<section class="grid" id>
Because here the id field is empty. The lonely “id” looks not right. :slight_smile:

That’s two different things. Every layout has an id that is stored in the content file.

<?= $layout->attrs()->id()->isNotEmpty() ? 'id="' . $layout->attrs()->id() . '"' : ''?>
1 Like

Thanks pixelijn for the “id” solution :+1: