Hooks
With hooks you can intercept all kinds of Kirby events to inject your own code, for example, react when a user uploads a file or when they save a page. See below for more details.
-
file.changeName:after
-
file.changeName:before
-
file.changeSort:after
-
file.changeSort:before
-
file.create:after
-
file.create:before
-
file.delete:after
-
file.delete:before
-
file.replace:after
-
file.replace:before
-
file.update:after
-
file.update:before
-
kirbytags:after
-
kirbytags:before
-
kirbytext:after
-
kirbytext:before
-
language.create:after
-
language.create:before
-
language.delete:after
-
language.delete:before
-
language.update:after
-
language.update:before
-
page.changeNum:after
-
page.changeNum:before
-
page.changeSlug:after
-
page.changeSlug:before
-
page.changeStatus:after
-
page.changeStatus:before
-
page.changeTemplate:after
-
page.changeTemplate:before
-
page.changeTitle:after
-
page.changeTitle:before
-
page.create:after
-
page.create:before
-
page.delete:after
-
page.delete:before
-
page.duplicate:after
-
page.duplicate:before
-
page.render:after
-
page.render:before
-
page.update:after
-
page.update:before
-
route:after
-
route:before
-
site.changeTitle:after
-
site.changeTitle:before
-
site.update:after
-
site.update:before
-
system.exception
-
system.loadPlugins:after
-
user.changeEmail:after
-
user.changeEmail:before
-
user.changeLanguage:after
-
user.changeLanguage:before
-
user.changeName:after
-
user.changeName:before
-
user.changePassword:after
-
user.changePassword:before
-
user.changeRole:after
-
user.changeRole:before
-
user.create:after
-
user.create:before
-
user.delete:after
-
user.delete:before
-
user.login:after
-
user.login:before
-
user.logout:after
-
user.logout:before
-
user.update:after
-
user.update:before
Details
Hooks allow you to react on Kirby events like file uploads, page updates etc.
Hooks can execute code, but you can't return anything from them or redirect anywhere. If you try to, an error is thrown in the Panel.
Kirby provides two variants of each hook: before
and after
hooks.
Before
hooks
A before
hook is triggered before an action is executed, i.e. before a page is actually updated, a file uploaded, a route called etc.
Typical use cases for before
hooks include:
- Throw an error to prevent certain users from executing an action in general or under certain circumstances.
- Store information in the session.
- Log something before an action is executed.
- …
After
hooks
An after
hook is triggered right after the action was executed. Some typical use cases for these hooks are:
- Automatically resize a huge image and save a smaller version instead.
- Modify user entered information when a user saves the page.
- Log something when an action is executed.
- …