In my twig template, I have the following code:
<td>{{ object.content|length > 50 ? object.content|raw|slice(0, 50) ~ '...' : object.content|raw }}</td>
My object object.contentis a string like this:
<p>Nullam quis risus eget urna mollis ornare vel eu leo. Donec ullamcorper nulla non metus auctor fringilla.</p>
I would like to output a string without tags <p>, <b>, ... Therefore, I add a filter |raw. I also want to print 50 characters of the entire string .
50 character slicing works, but it still shows tags <p>, ...
Now when I do this:
<td>{{ object.content|raw }}</td>
It shows a string without tags <p>. But when I add the slice filter, it does not work ... I also tried to set the variable before exiting as follows:
{% set rawcontent = object.content %}
<td>{{ rawcontent|slice(0, 50) ~ '...' }}</td>
But the same result ... How can I fix this?