RichText Filter and Field Limitations?

669 views
Skip to first unread message

Ryan Nevius

unread,
Apr 26, 2015, 10:00:13 AM4/26/15
to wag...@googlegroups.com
Perhaps I'm using or understanding it wrong...but the richtext filter doesn't appear to be working for me. 

What I'm trying to do: Paste a block of HTML into a RichTextField(). This HTML looks something like:

<div class="ui section divider"></div>
<div class="ui page grid">
    <div class="row">
        <div class="center aligned column">
            <h2>We Design Things</h2>
            <h4>Inspire the imagination of buyers by blah blah.</h4>
            <div class="small spacer"></div>
            <h4><strong>Discuss your unique project today!</strong></h4>
            <button>Schedule a Consultation</button>
        </div>
    </div>
</div>

When I use the |richtext filter in my template, I'm still getting back escaped HTML.

What I tried:
  1. Use the vanilla Django |safe filter and {% autoescape off %} tags
  2. Enable the Hallo HTML source editor, as described in this GitHub issue
Is there something about RichText fields that won't allow me to input HTML directly, and have it render as HTML in my template? I can obviously use a TextField...but hoped this field would work instead.

Thoughts?

Matthew Westcott

unread,
Apr 27, 2015, 6:52:45 AM4/27/15
to wag...@googlegroups.com
Hi Ryan,

The purpose of the RichTextField is to allow people to enter formatted text *without* needing to work in raw HTML - if you paste HTML code into it, it will be treated just like any other bit of text that happens to have a bunch of angle brackets in it, and displayed that way on the template.

It is possible to sneak custom HTML into a rich text field using the Hallo HTML source editor in combination with custom whitelisting rules - but the further you depart from basic text formatting, the more hoops you have to jump through, and in this case, you really are better off using a plain TextField.

However, I'd really recommend thinking about how you can redesign your page model / template to better fit your needs. Wagtail is all about separating content from presentation, and here you have a lot of structural markup that really belongs in the template rather than the page content. This might entail having a specific 'CallToActionPage' page type with specific fields for 'call to action header', 'button text' and so on. Or if this piece of content is one of many sections that might appear within the flow of a page, the StreamField feature introduced in Wagtail 1.0 beta might be a better fit... http://docs.wagtail.io/en/v1.0b1/pages/streamfield.html

Cheers,
- Matt

Ryan Nevius

unread,
Apr 27, 2015, 6:57:39 AM4/27/15
to wag...@googlegroups.com
Thanks for the info, Matt. As you mentioned, messing with Hallo got messy fast. I ended up creating a special page model for call-to-action sections.

Related to the above: Is the an advantage to using Pages as opposed to "snippets" for something like this? As these individual sections don't need their own URLs, it almost seems that a Snippet would be more appropriate.

Thanks again,

Ryan

Matthew Westcott

unread,
Apr 27, 2015, 7:18:42 AM4/27/15
to wag...@googlegroups.com
Yep, a snippet would be a good solution for this too, particularly if the same call-to-action gets re-used across multiple pages.

Cheers,
- Matt
Reply all
Reply to author
Forward
0 new messages