Skip to content

Kirby 3.9.8

Snippets

Add your own snippet loader

/site/plugins/snippet-engine/index.php
use Kirby\Template\Snippet;

Kirby::plugin('my/snippet', [
    'components' => [
        'snippet' => function (Kirby $kirby, string $name, array $data = [], bool $slots = false): Snippet|string {
            return YourSnippetLoader::factory($name, $data, $slots);
        }
    ]
]);

Parameters

Name Type Default Description
$kirby * Kirby\Cms\App Kirby instance
$name * array|string|null Snippet name
$data array [ ] Data array for the snippet
$slots bool false

Return type

Kirby\Template\Snippet|string