How do install a Twig extension in Craft? Not write my own extension, but install an extension that exists. I want to install the extensions extension. There are a number of posts that describe how to write your own extension, but I can't see how to just install one. The Twig docs says add this: $twig->addExtension(new Twig_Extensions_Extension_Array()); but obviously I don't want to edit core Craft.

I found this - How do you add a core twig extension in plugins using addTwigExtension()?, but the responses just convince the poster that he doesn't need to use that extension. What if he wanted to use it? How do you install it?

1 Answer 1


The BreakAndContinue plugin is an example of a plugin that adds a simple twig extension. I would start with that, and modify it to add the extensions extension (I assume that is this: https://github.com/twigphp/Twig-extensions ?) You might need to tweak the Twig PHP to get files to load etc., but not core Craft, since this will be a plugin.

  • ok cool I'll give it a go. Yeah twig-extensions is the one I want. I just need to randomise an array so shuffle looks good. I could easily write my own code to do it, but I thought I'd use this as an exercise to see how to add extensions Sep 15, 2015 at 4:46
  • yep it worked, probably more trouble than it was worth just get a wrapper on the php shuffle function, but now I know how to do it! thanks Sep 15, 2015 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.