Skip to content

Instantly share code, notes, and snippets.

@PabloLefort
Created September 27, 2016 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PabloLefort/00be2b09a26791a467fa2aec83a6e195 to your computer and use it in GitHub Desktop.
Save PabloLefort/00be2b09a26791a467fa2aec83a6e195 to your computer and use it in GitHub Desktop.
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