Drupal 8 trim body text in twig

Sometimes you need a body text that is trimmed. No need to install contrib modules. Here's a little snippet:

{% set text = content.body|render|striptags %}
{{ text|length > 200 ? text|slice(0, 200)|raw ~ '...' : text|raw }}

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!