I’m currently experimenting with snippets with slots for general layout purposes.
The documentation says:
If a snippet is still open at the end of the template, Kirby automatically closes it.
This is really handy when creating general purpose layouts as you can just declare your layout on top of the template:
<?php snippet('html', slots: true) ?> <p>My content</p>
So I wanted to take this a step further and have two layout snippets:
- one to create the HTML skeleton
- and another to create different column structures bases on the page context.
<?php snippet('html', slots: true) ?> <?php snippet('two-columns', slots: true) ?> <p>My content</p>
This only return the second
two-columns layout, the outer
html layout is ignored. It only works as intended if I add at least one closing
<?php snippet('html', slots: true) ?> <?php snippet('two-columns', slots: true) ?> <p>My content</p> <?php endsnippet() ?>
It’s kind of logical why this is happening, but it removes the simplicity of the layout declaration on top because you always have to think about the closing tag as well. So I was asking myself, if this was a technical limitation or if it would be possible for Kirby to close all open snippets automatically at the end of the template file?