Kirby theme as a plugin

I’m currently working on my first Kirby theme and I keep seeing references left and right to “theme as a plugin / theme based on a plugin” – is there any documentation on this topic to be found somewhere?
(apologies if this is an obvious question)

No, there is no documentation, but what it basically means that you register all blueprints, templates, snippets etc. in a plugin instead of putting those files into the respective site folders. Advantage is that you can easily overwrite those plugin files with files with the same name in the site folder.

So I’m guessing my next stop is the plugin section of the Kirby docs then? (haven’t looked at those yet)

Yes!

1 Like

Basically something along these lines…

<?php

@include_once __DIR__ . '/vendor/autoload.php';

Kirby::plugin('yourname/kirby3-themename', [

    'snippets' => [
        'yournamespace/thing'    => __DIR__ . '/snippets/thing.php'
        // more as required
    ],

    'blueprints' => [
      'yournamespace/thing'    => __DIR__ . '/blueprints/thing.yml'
      // more as required
    ],

    'templates' => [
        'thing'    => __DIR__ . '/templates/thing.php'
        // more as required
      ],

]);

Then you can store the files within your plugins folder structure

2 Likes

Can we have an updated best practice example for Kirby 4.

the plugin basics are the same in k3 and k4