What I'm looking for is something that limits the output without breaking tags. Let's say that I have some content for example coming from FCK / MCE:
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum </p>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem </p>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem </p>
Now for example if I did something like {{ output|raw[:10] ~ '...' }}
I would get:
<p>lorem i...
But instead I would like to get:
<p>lorem i...</p>
Any ideas how to accomplish this?
If you are sure that it starts with
<p>
and ends with</p>
use this:If you want to find and replace something in your output you can
You should try available extension of twig to truncate text in Twig & Symfony2.
Your text is in html so first get plain text using "striptags" filter then apply "truncate" filter of twig.
but first you must enable Twig-Text-Extension as following
or in symfony2
Following is available options for truncate filter
1 - only truncate
2 - Set second parameter if you want to preserve whole words.
3 - Set third parameter if you want use your own separator instead of "..."
for more detail about twig text extension visit http://twig.sensiolabs.org/doc/extensions/text.html