Learn how to use template hooks in Craft CMS to customize your website! Template hooks let you add code and inject dynamic HTML into your site's templates without touching the original files. This keeps your code clean and makes updates a breeze. We'll show you practical examples and best practices for using this powerful feature.
Craft 5
In this video, watch as Ryan walks through how to use template hooks in Craft CMS to inject code or alter the context of a template.
First, we learn about how Ryan uses hooks on CraftQuest to inject necessary JavaScript in order to get system timezone information. Then we look at what a hook returns when you intercept it and dump out the template context. Finally, we create our own hook to inject a subnavigation into specific templates that are part of a content section.