Extending Twig in Craft CMS

Creating Another Twig Function

We create another Twig function but this time we pass in an array of words to use as replacements.

In this exam­ple, we’re going to manip­u­late text passed into the func­tion using val­ues passed into the func­tion and then output.

Here’s how we’ll use it in our Twig template:

{{ plantify(['soy', 'beans', 'tofu', 'seitan', 'mushrooms', 'Beyond Burger', 'Tofurkey'], text) }}

Extending Twig in Craft CMS is made up of the following videos: