Download the PHP package kenshodigital/kirby-snippet without Composer
On this page you can find all versions of the php package kenshodigital/kirby-snippet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kenshodigital/kirby-snippet
More information about kenshodigital/kirby-snippet
Files in kenshodigital/kirby-snippet
Package kirby-snippet
Short Description Adds controllers to Kirby snippets.
License MIT
Informations about the package kirby-snippet
Snippet for Kirby
Adds controllers to Kirby snippets.
General
Brings Kirby’s mechanism for template controllers to snippets and blocks. This provides a unified and consistent way to offload logic and prepare data for cleaner templates and snippets.
How it works
The plugin uses Kirby’s native features and extension points. It looks for a controller whenever a snippet is called, and passes the resulting controller data to the snippet.
Since blocks are also just rendered as snippets under the hood, this works for blocks as well.
Installation
Usage
Snippet controllers are loaded from a snippets
folder under the configured root for controllers.
Just as template controllers and templates, snippet controllers are identified by the same filename as their corresponding snippets.
Snippet | Snippet Controller |
---|---|
/site/snippets/article.php |
/site/controllers/snippets/article.php |
/site/snippets/blocks/video.php |
/site/controllers/snippets/blocks/video.php |
As usual, snippet controllers are anonymous functions that receive the snippet data as arguments and return variables as an associative array. The resulting controller data is then merged with the original snippet data, before everything is passed to the snippet.