I’m working on a project where I want to combine the Kirby layout field at the page level with custom blocks that also use layouts internally (nested layouts). My goal is to allow editors to create flexible sections on a page, and inside certain blocks (like tabs or cards), I’d like to offer additional layout options—so that each tab or card can itself have a layout with multiple columns and blocks.
What I’m trying to achieve:
The main page uses the layout field for flexible section and column management.
- Inside some custom blocks (for example, a “Tabs” block), I want to provide another layout field, so each tab can have its own internal layout and blocks.
- Editors should be able to add any type of content inside each tab/card, including text, images, and even further structured layouts.
I got this error back -
Kirby\Cms\LayoutColumn::span(): Return value must be of type int, float returned
But only if i use default and tabs together - rest of the page work’s normal.
/blocks/tabs.yml
name: Tabs
fields:
tabs:
label: Tabs
type: structure
fields:
title:
label: Tab-Titel
type: text
content:
label: Tab-Inhalt
type: layout
layouts:
- "1/1"
- "1/2, 1/2"
- "1/4, 1/4, 1/4, 1/4"
- "1/3, 2/3"
- "2/3, 1/3"
- "1/3, 1/3, 1/3"
fieldsets:
- text
- image
- heading
/pages/default.yml
title: Site
tabs:
pages:
label: Seiten
columns:
- width: 2/3
sections:
fields:
layout:
type: layout
layouts:
- "1/1"
- "1/2, 1/2"
- "1/4, 1/4, 1/4, 1/4"
- "1/3, 2/3"
- "2/3, 1/3"
- "1/3, 1/3, 1/3"
fieldsets:
- heading
- text
- image
- tabs
/templates/default.php
<?php foreach ($layout->columns() as $column): ?>
<?php $span = round($column->span(6)); ?>
<div
class="<?= $centercCntent->isTrue() ? 'h-full' : '' ?> px-4 2xl:px-0 py-2 lg:py-8 <?= ($span == 6) ? 'basis-full' : (($span == 3) ? 'basis-1/2' : 'basis-' . $span . '/6') ?>">
<?= $column->blocks() ?>
</div>
<?php endforeach ?>
/templates/snippet/tabs.php
<?ph ``` p foreach ($tab->content()->toLayouts() as $layout): ?><?php foreach ($layout->columns() as $column): ?>
<?php $span = (int) round($column->span(6)); ?>
<div class="basis-<?= $span ?>/6">
<?= $column->blocks() ?>
</div>
<?php endforeach ?>
<?php endforeach ?>