10/1/2019 - 4:45 AM

Using the striptags twig filter in Drupal

The Problem:

If you use {{ some_item|striptags('<a><p><br>') }}, then Drupal will render your content with the allowed tags URL encoded so that they appear on the page (rather than being the lovely, functional HTML they were intended to be...)

The Solution:

Use {{ some_item|striptags('<a><p><br>')|raw }}, which tells Drupal to go ahead and render the specified tags (such as paragraphs or anchors) as actual tags, rather than translate them to text.