Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wagtail template filter to resolve html
"""
When editing the content use the brackets:
[[ <iframe>..</iframe> ]]
And after, use it in templates like this:
{{ page.body|resolve_html|richtext }}
"""
# templatetags/mytags.py
from django import template
register = template.Library()
@register.filter
def resolve_html(value):
new = value.replace('<p>[[', '')
new = new.replace(']]</p>', '')
new = new.replace('&lt;', '<')
new = new.replace('&gt;', '>')
return new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment