3

I'd like to add the Text extension:

http://twig.sensiolabs.org/doc/extensions/index.html#extensions-install

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

(this could've been installed by default)

3
  • What's the advantage of the truncate filter? What does it do that you can't achieve with slice?
    – carlcs
    Commented Jan 20, 2015 at 14:02
  • Did you see this question: "Best method of text truncating"?
    – carlcs
    Commented 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
    Commented Dec 1, 2016 at 17:42

1 Answer 1

2

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.

1
  • 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
    Commented Dec 1, 2016 at 17:41

Your Answer

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

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