title: How to truncate text and use the raw filter in Twig
body: <p>The issue is that the <a href="https://twig.symfony.com/doc/2.x/filters/raw.html" rel="nofollow noreferrer">raw Twig filter</a> must go at the end of the chain for it to work correctly and replace the HTML entities with their corresponding characters. This causes a problem as I need to also use the truncate function. The truncation is happening correctly but in the instances where the truncation happens in the middle of one of the HTML entity strings the raw function then fails to remove this entity.</p>
  
  <p>Current solution:      </p>
  
  <pre><code>{{ BlogPost.description|striptags|truncate(80)|raw }}
  </code></pre>
  
  <p>Input string:</p>
  
  <pre><code>&lt;p&gt;It supports your pupils to think like scientists &amp;ndash;&amp;nbsp;but that doesn&amp;rsquo;t&amp;nbsp;mean it&amp;#39;s only for science!&lt;/p&gt;"
  </code></pre>
  
  <p>What the current solution achieves:</p>
  
  <pre><code>It supports your pupils to think like scientists – but that doesn&amp;rsq...
  </code></pre>
  
  <p>What I want to achieve:</p>
  
  <pre><code>It supports your pupils to think like scientists – but that doesn't m...
  </code></pre>