I got a rich text field.
I made an excerpt with striptags slice and raw twig functions.
It works fine most of the time (raw close tags when slice cuts inside a <p>).

<div>{{ textBlock.text | striptags("<p><br><div><li><em>") | slice(0, 275) | raw }}...</div>

But sometimes it completely breaks and put plenty of empty tags anywhere :

enter image description here

I noticed that it happened when the original text is cut in the middle of double tags like :
<p><em>Some text cut by slice function here</em></p>

Real bug no ?


Raw doesn't close tags tags for you, it just allows them to be processed rather than printed only.

The only reason you are seeing closing tags I'm guessing is because your inspector (chrome/safari) is adding them in. Do "view source" to see the real output.

Your problem here is just rogue open tags

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.