Dynamic snippets suggestion system

Hi there !

I’m trying to create a snippet suggestion system with a plugin.
I register a single router snippet wich build suggestions snippet base on some parameter like blueprint, display (see code).
But if my snippets suggestions are not registered inside my plugin index file it doesn’t work.

I register my snippet router :

Kirby::plugin('db/helper', [
'snippets' => [
'displays/pages/_' => __DIR__ . '/snippets/displays/pages/_.php',

An I would like its to chosse the first template finded like code below (in comments, the suggestions)


$display = $display ?? 'default';
$blueprint = $item->blueprint()->name();
$params = $params ?? [];

        // displays/pages/news/card
        'displays/' . $blueprint . '/' . $display,
        // displays/pages/card
        'displays/' . explode('/', $blueprint)[0] . '/' . $display,
        // displays/pages/default
        'displays/' . explode('/', $blueprint)[0] . '/default',
        // displays/card
        'displays/' . $display,
        // displays/default
        'item' => $item,
        'params' => $params

The main advantage is to provide a generic plugin which handle a default rendering.
Then, in the site folder, I would like to be able to override plugin default rendering by including new files… I can’t register all suggestion, as I don’t know them in advance…

How to do that ?

In fact it works when the a suggested snippet file is located in site directory.
But it doesn’t work when the suggested snippet is located in my plugin directory.
How can I do that ?

That’s right, snippets in your plugin need to be registered. But I don’t understand why you can’t register the snippets in your plugin in advance.

I didn’t know that. It is because I use my plugin as a kind of starter kit for multiples projects, so I can’t predict the custom blueprint needed for them. But I would like to put some defaults templates inside the plugin (which I will declare, adopted solution).

Btw it also fully logic to put the content templates inside the site folder as they are subject to change. :grinning:

Thank you Texnixe !