Download the PHP package afbora/kirby-template-hooks without Composer
On this page you can find all versions of the php package afbora/kirby-template-hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download afbora/kirby-template-hooks
More information about afbora/kirby-template-hooks
Files in afbora/kirby-template-hooks
Package kirby-template-hooks
Short Description Enable page and file template hooks and user role hooks for Kirby
License MIT
Homepage https://github.com/afbora/kirby-template-hooks
Informations about the package kirby-template-hooks
Kirby Template Hooks
Kirby template hooks allow you to manage hooks for page and file templates and user roles more easily.
Instead of checking the template in every page.update:after hook, you can register a hook only for the pages with the product template: page.product.update:after.
Requirements
- Kirby 5 or 6
- PHP 8.2 or newer
For Kirby 3 and 4, use version 1.x.
Installation
Installation with composer
Add as git submodule
Usage
Pages
Usage: page.TEMPLATE_NAME.ACTION_NAME:before/after
The template name is the intended template of the page, i.e. the name of its content file (product.txt).
Files
Usage: file.TEMPLATE_NAME.ACTION_NAME:before/after
The template name is the template field of the file. Files without a template use default, like their files/default blueprint:
User avatars are files with the avatar template, so file.avatar.create:after runs for new avatars.
Users
Usage: user.ROLE_NAME.ACTION_NAME:before/after
Arguments
Template hooks receive exactly the same arguments as the core hooks, e.g. $page, $values, $strings and $languageCode for page.update:before. You can find them in the hooks reference. The $event argument is the template event (page.product.update:after).
Like core hooks, template hooks can return a modified model to change the result of the action:
Actions
| Type | Actions |
|---|---|
page |
changeNum, changeSlug, changeStatus, changeTemplate, changeTitle, create, delete, duplicate, move, update |
file |
changeName, changeSort, changeTemplate, create, delete, replace, update |
user |
changeEmail, changeLanguage, changeName, changePassword, changeRole, changeSecret (Kirby 6), changeTotp (Kirby 5), create, createAvatar (Kirby 5.4+), delete, deleteAvatar (Kirby 5.4+), replaceAvatar (Kirby 5.4+), update |
changeTemplate and changeRole run the before hook for the old template or role and the after hook for the new one:
Upgrading from 1.x
- Template hooks get all arguments of the core hook. The names of the arguments didn't change, so existing hooks keep working.
- Values returned by template hooks are now used like the ones of core hooks. Before, they were ignored.
- Files without a template run
file.default.*hooks instead offile..*. - New:
page.move,file.changeTemplateand user role hooks.