By default wagtail displays its add/edit view for all pages with two tabs — “Content” and “Promote” — whose contents you define for each page type by setting the .content_panels and .promote_panels like so:

 HomePage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('body', classname="full"),
    InlinePanel(HomePage, 'carousel_items', label="Carousel items"),
    InlinePanel(HomePage, 'related_links', label="Related links"),
]

HomePage.promote_panels = [
    MultiFieldPanel(Page.promote_panels, "Common page configuration"),
]

You can also customize the set of panels themselves.  For example, a particular page type might not need to have a “Promote” tab, or you might want a separate “Sidebar” tab to better organize the editor experience.

Here’s how to do that; suppose you have a custom page class called CustomPage:

from wagtail.wagtailadmin.views.pages import (PAGE_EDIT_HANDLERS,
                                              TabbedInterface,
                                              ObjectList)

PAGE_EDIT_HANDLERS[CustomPage] = TabbedInterface([
        ObjectList(CustomPage.general_panels, heading="General"),
        ObjectList(CustomPage.content_panels, heading="Content"),
	ObjectList(CustomPage.sidebar_panels, heading="Sidebar"),
	])

Note that if you do this, your CustomPage class should define the above attributes (in this example, general_panels, content_panels and sidebar_panels) instead of the typical content_panels and promote_panels. 

I’ve filed a pull request with a cleaner API for the sake of argument, though I guess I’m just curious whether this feature can be relied on moving forward.

Filed May 10th, 2014 under wagtail
  1. HI,

    is this code for wagtail now or an example of how you’d like it to work?

    Joss

    Comment by Joss on June 13, 2014 at 8:28 am

  2. This code works for a wagtail project now - no changes needed to the wagtail codebase itself.

    Comment by egj on June 13, 2014 at 8:35 am

  3. Cool. Thanks

    Comment by Joss on June 13, 2014 at 5:16 pm

Leave a comment

To comment on this blog you will need to log in or create an account first.