striptags Filter

Coding

Documentation

Strips HTML tags.

Variable

poem_html = '''<article>
    Much to his Mum and Dad’s <em>dismay</em>,<br>
    Horace <em>ate himself</em> one day.<br>
    <hr>
    He <em>didn’t stop</em> to say his grace,<br>
    He just sat down and <strong>ate his face</strong>.
    <hr>
    <strong>“We can’t have this!”</strong> His Dad declared,<br>
    “If that lad’s ate, <strong><em>he should be shared.</em></strong>”
</article>'''

Template

{{ poem_html|striptags }}

Result

Much to his Mum and Dad’s dismay,
Horace ate himself one day.

He didn’t stop to say his grace,
He just sat down and ate his face.

“We can’t have this!” His Dad declared,
“If that lad’s ate, he should be shared.”

Commentary

This can be useful for converting a template HTML email to text when you want to send both HTML and text version of an email.


Did we get something wrong? Is there a use case for the striptags filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on Sept. 16, 2020, 7:34 p.m. EST