How do I register Layouts in plugins?

Trying to make use of GitHub - getkirby/layouts: Extend Kirby’s templates with a powerful layout system (version 1.0.1) in my sites. I define all of my templates in a plugin for easy reuse.

Changes:

  • Added /layouts/default.php
  • Updated index.php of plugin to reference the layout.
  • Changed my /templates/default.php to use layout.

layouts/default.php

<?php snippet('start'); ?>

<div id="page" class="flex flex-col min-h-screen">
    <?php snippet('header') ?>
    <div class="flex-grow">
        <main>
        <?php slot() ?>

        <?php endslot() ?>
        </main>
    </div>
    <?php snippet('footer') ?>
</div>

<?php snippet('end') ?>

Plugin index.php

'layouts'     => [
    'default' => __DIR__ . '/layouts/default.php',
],

templates/default.php

<?php layout() ?>

<?php snippet('page-builder') ?>

Seems to only work when layouts/default.php lives in the /site folder. I need it to work when it lives in my plugin. Any way to make this work?

Just posting the answer here as well in case anyone finds this:

No, you cannot register your layouts from a plugin, because there is no such things as a layouts extension in Kirby.

The layouts are loaded from from the /site/layouts folder.

return Tpl::load(kirby()->root('site') . '/layouts/' . static::$name . '.php', array_merge(Layout::$data ?? [], $data));

If and when the Layouts plugin makes it into the core, it would of course make sense to also add such an extension.

However, as far as I know, there is currently no roadmap for it and thus also no ETA.

Feel free to make a suggestion on our feedback channel

Thanks @texnixe. I created an issue on the Layouts Plugin repo to request this ability: Add ability to define layouts in plugins · Issue #5 · getkirby/layouts · GitHub

Also posted in the Feedback Channel: Layouts Plugin: Support registering layouts in plugins · Kirby Feedback