The setup work in a Craft module to support a Twig extension.
This setup will work for either a Craft module or plugin. We’ll use a Craft module for this course since it’s the easiest to get up and running. If you don’t yet know how to code a Craft module, check out my course on it My First Craft Module.
There are two steps to getting a basic framework for a Twig extension set up in Craft. First, we need to create the extension class in our Craft plugin or module. The second step is that to register the extension with Craft vis the registerTwigExtension()
method. This method tells Craft we have additional Twig code to run when it spins up an instance of the application.
Let’s first set up our basic class file and then register our extension in the main class file of our module.
Extending Twig in Craft CMS is made up of the following videos: