Adding Template Hooks in Craft CMS

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.

In this video, watch as Ryan walks through how to use tem­plate hooks in Craft CMS to inject code or alter the con­text of a template.

First, we learn about how Ryan uses hooks on CraftQuest to inject nec­es­sary JavaScript in order to get sys­tem time­zone infor­ma­tion. Then we look at what a hook returns when you inter­cept it and dump out the tem­plate con­text. Final­ly, we cre­ate our own hook to inject a sub­nav­i­ga­tion into spe­cif­ic tem­plates that are part of a con­tent section.