2026 Community Survey results are here! See how the Craft CMS community works. results are live!

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) }}
Instructor
Ryan Irelan
Level
Intermediate
Date Published
June 14, 2021
Ryan Irelan

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.