kenshodigital / kirby-snippet
Adds controllers to Kirby snippets.
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:kirby-plugin
Requires
- php: ^8.3
- getkirby/cms: ^4.1
- getkirby/composer-installer: ^1.2
README
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
composer require kenshodigital/kirby-snippet ^1.0
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.
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.