I'd like to add the Text extension:


Which seems very useful because of the truncate functionality. Any idea on how to accomplish this?

(this could've been installed by default)

  • What's the advantage of the truncate filter? What does it do that you can't achieve with slice?
    – carlcs
    Jan 20, 2015 at 14:02
  • Did you see this question: "Best method of text truncating"?
    – carlcs
    Jan 20, 2015 at 14:08
  • I appreciate these comments but neither of them address the question asked. 1) Slicing a string is a very simple operation. Truncating text when markup is present, without destroying the underlying DOM, is a very different operation and there are, as of yet, no perfect solutions for this. The major alternative that works in many cases has issues, as outlined below. 2) The answer to the linked question of "Best method of text truncating" is the Hacksaw plugin. Hacksaw is not a perfect solution and has bugs in the way it truncates with markup present, specifically around char count control
    – Gavin
    Dec 1, 2016 at 17:42

1 Answer 1


Check out the Craft Plugin documentation on adding a Twig extension with a plugin. There is no clean way to add extensions manually without a plugin, as the changes might be overridden with Craft updates.

  • Can you expand on this answer? It points in a direction but doesn't offer anything concrete in terms of the question addressed. There are many guides on adding Twig extensions, but none that address specifically importing the Twig Extensions lib, which is different from importing a hand-crafted Twig plugin, which is rather straightforward in of itself.
    – Gavin
    Dec 1, 2016 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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