<p>The <a href="https://github.com/marionnewlevant/craft-mnbreakandcontinue" rel="nofollow">BreakAndContinue</a> 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: <a href="https://github.com/twigphp/Twig-extensions" rel="nofollow">https://github.com/twigphp/Twig-extensions</a> ?) You might need to tweak the Twig PHP to get files to load etc., but not core Craft, since this will be a plugin.</p>

CC BY-SA 3.0
2015-09-15T04:46:44.410Z
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
andrew wisener
CC BY-SA 3.0
2015-09-15T05:11:45.427Z
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
andrew wisener
CC BY-SA 3.0
2015-09-15T03:34:15.187Z
2015-09-15T04:16:08.680Z
2015-09-15T04:16:08.680Z
Marion Newlevant
<p>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: <code>$twig-&gt;addExtension(new Twig_Extensions_Extension_Array());</code> but obviously I don't want to edit core Craft. </p>

<p>I found this - <a href="https://craftcms.stackexchange.com/questions/8223/how-do-you-add-a-core-twig-extension-in-plugins-using-addtwigextension">How do you add a core twig extension in plugins using addTwigExtension()?</a>, 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?</p>

<templating>
How to install a Twig extension
# How to install a Twig extension

(Asked by: username_0 on 2015-09-15)

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()?](https://craftcms.stackexchange.com/questions/8223/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?

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2015-09-15. Score: 1

The [BreakAndContinue](https://github.com/marionnewlevant/craft-mnbreakandcontinue) 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.

> **Comments:**
> **username_0**: 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  
> **username_0**: 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  

---

