$field->toLayouts()
Parse layouts and turn them into Layout objects
Return type
How to render layouts in templates?
Using the toLayouts
field method, you can retrieve a Layouts collection - a collection of Kirby\Cms\Layout
objects:
Calculate the column span value
Each column in a layout has a $column->width()
method which will return the width defined in the blueprint. (i.e. 1/2
) but for many grid systems you need to know how many columns the current column should span in the grid. This can be done with the $column->span()
method. The method calculates with a 12-column grid by default. So for example, if your column width is 1/2
the span method would return a value of 6. If you are working with a different kind of grid system you can pass the number of columns like this: $column->span(6)
:
Working with individual blocks
In some cases, you might even want to controll the way blocks within layouts are rendered. $column->blocks()
will return a blocks collection that you can work with and create another nested foreach loop.
Passing the layout object to the block snippet
If you need to access the layout object in a block snippet, you need to pass it to the snippet manually.