在wagtail admin中添加html到页面编辑视图

时间:2018-01-23 10:39:49

标签: admin customization wagtail

如何在wagtail admin的“页面编辑视图”中添加一些文本或html?我想给他们一些关于他们正在工作的页面的更多信息。

(编辑可以在文本中使用$ variables $,我想向他们展示特定页面的所有可用变量。)

Example how it should look like

1 个答案:

答案 0 :(得分:2)

可以为编辑界面定义自定义面板。 Wagtail有FormSubmissionsPanel面板(参见the source code),在编辑a form page时会显示一些表单提交。您可以将它作为起点。

如果您只想为编辑器呈现包含一些其他信息的静态模板,那么您的面板定义将类似于:

class BaseInfoPanel(EditHandler):
    template = "path/to/your/template.html"

    def render(self):
        return mark_safe(render_to_string(self.template))


class InfoPanel(object):
    def __init__(self, heading=None):
        self.heading = heading

    def bind_to_model(self, model):
        return type(str('_InfoPanel'), (BaseInfoPanel,), {
            'model': model,
            'heading': self.heading or "Additional info",
        })

在您的网页模型中,您可以将其用作

class MyPage(Page):
    # fields...

    content_panels = Page.content_panels + [
        InfoPanel(),
        # or InfoPanel("My info panel") to specify heading for a panel.
        # other panels ...
    ]
相关问题