I am using twig to render a view and I am using the striptags filter to remove html tags. However, html special chars are now rendered as text as the whole element is surrounded by "". How can I either strip special chars or render them, while still using the striptags function ?
Example :
{{ organization.content|striptags(" >")|truncate(200, '...') }}
or
{{ organization.content|striptags|truncate(200, '...') }}
Output:
"QUI SOMMES NOUS ? > NOS LOCAUXNOS LOCAUXDepuis 1995, Ce lieu chargé d’histoire et de tradition s’inscrit dans les valeurs"
I had a similar issue, this worked for me:
If it could help someone else, here is my solution
You can also add a trim filter to remove spaces before and after. And then, you truncate or slice your organization.content
EDIT November 2017
If you want to keep the "\n" break lines combined with a truncate, you can do
{{ organization.content|striptags|truncate(140, true, '...')|raw|nl2br }}
Arf, I finally found it :
I am using a custom twig filter that just applies a php function:
Now it renders correctly
My php extension:
I had the same problem, I resolved it byt this function below, using strip_tags.
I was trying some of, among others, these answers:
And still got strange characters in the final form. What helped me, is putting the
raw
filter on the end of all operations, i.e: