Now we set our sights on creating a Twig function. This is quick and easy because all of the supporting code is already there.
With our Twig filter done, let’s focus on a function. The difference between a filter and function is that a filter is about manipulating data passed into the filter and then returning it. A function, on the other hand, is for when you want to generate something, like content.
But a function can also be helpful when you need to pass in some arguments that will be used to manipulate or control output of the data.
In our case, we want to build two functions (one this video and one in the next). One will output a list of plant-based ingredients. This is our content generation example. The other will transform any text passed into it along with the replacement values passed in as an argument.
We already have our Twig extension class created and initialized in the module class file, so we can focus solely on creating a couple of functions.

I am the creator of CraftQuest, a web developer, and former software team manager. I spend most of my time improving CraftQuest with code and courses. When I'm not in front of the computer, I spend my time with my family, and running on the roads and trails of Austin, TX.