<p>Check out the <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#addTwigExtension" rel="nofollow">Craft Plugin documentation on adding a Twig extension with a plugin</a>. There is no clean way to add extensions manually without a plugin, as the changes might be overridden with Craft updates.</p>

CC BY-SA 3.0
2016-12-01T17:41:36.287Z
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
CC BY-SA 3.0
2015-02-01T02:01:00.423Z
2015-02-01T02:01:00.423Z
Aaron Berkowitz
<p>I'd like to add the Text extension: </p>

<p><a href="http://twig.sensiolabs.org/doc/extensions/index.html#extensions-install" rel="nofollow">http://twig.sensiolabs.org/doc/extensions/index.html#extensions-install</a></p>

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

<p>(this could've been installed by default)</p>

CC BY-SA 3.0
2015-01-20T14:02:26.453Z
What's the advantage of the `truncate` filter? What does it do that you can't achieve with [`slice`](http://twig.sensiolabs.org/doc/filters/slice.html)?
carlcs
CC BY-SA 3.0
2015-01-20T14:08:43.780Z
Did you see this question: ["Best method of text truncating"](http://craftcms.stackexchange.com/q/661/125)?
carlcs
CC BY-SA 3.0
2016-12-01T17:42:25.147Z
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
<templating>
How to get the Twig Text extension loaded
# How to get the Twig Text extension loaded

(Asked by: username_0 on 2015-01-20)

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)

**Tags:** templating

> **Comments:**
> **username_1**: What's the advantage of the `truncate` filter? What does it do that you can't achieve with [`slice`](http://twig.sensiolabs.org/doc/filters/slice.html)?  
> **username_1**: Did you see this question: ["Best method of text truncating"](http://craftcms.stackexchange.com/q/661/125)?  
> **username_2**: 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  

---

## 1 answers

### Answer by username_3 on 2015-02-01. Score: 2

Check out the [Craft Plugin documentation on adding a Twig extension with a plugin](http://buildwithcraft.com/docs/plugins/hooks-reference#addTwigExtension). There is no clean way to add extensions manually without a plugin, as the changes might be overridden with Craft updates.

> **Comments:**
> **username_2**: 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.  

---

