The order of KirbyText/KirbyTags hooks
When to use what type of KirbyText/KirbyTags hook
When you call the
kirbyText()/kt() field method, a lot of stuff happens to the raw text until the final result is rendered. During this process, four different hooks are called:
But in which order are these hooks called and what does this mean when we want to do something when these hooks are triggered?
The hooks are called in the following order:
kirbytext:before hook is triggered before any parsing is applied to the raw text. At this state, you can therefore manipulate the raw text of the field.
kirbytags:before hook kicks in directly afterwards, i.e. before KirbyTags are parsed, but after modifications through a
kirbytags:after hook kicks in after modifications through a
kirbytags:before hook and after all KirbyTags are parsed, but before Markdown and SmartyPants are parsed.
The final hook is the
kirbytext:after hook. Changes you make in this hook are applied to the rendered HTML after Markdown and SmartyPants are parsed. You could therefore use this hook to replace or modify HTML tags, e.g. replace all headings with anchor headings and stuff like that.
By choosing the right hook, you have full control over what modifications happen when and what further modifications are applied.