Slowwie Slowwie - 14 days ago 4
Twig Question

Twig truncate with read more link

I want to use the truncate filter of twig. And it works fine.

I wanted to use as a third argument a link to read more about the article.
But it does not work.

Here is the code:

{% set read_more_link %}
<a href="{{ path('course_news_show', {news:}) }}">... read more</a>
{% endset %}

<p>{{ entry.description|truncate(150, true, "read_more_link") }}</p>

What comes out is this:

"Lorem ipsum dolor sit met, <a href="/course/news/44">... read more </a>"

So, the link is displayed as text in the
How can I solve this problem. Can somebody help me with that ?

Best regards
Michael Brauner


Try to use raw filter after your truncate filter:

<p>{{ entry.description|truncate(150, true, "read_more_link")|raw }}</p>