复制默认的小部件模板并修改它以允许未转义的条目。
描述由 放置mapping.pt。它不能根据每个小部件进行覆盖 - 映射模板对于表单中的所有项目都是相同的。item_template您可以通过传递到小部件容器(表单、表单部分)来覆盖映射。未经测试的示例:
# No .pt extension for the template!
schema = CSRFSchema(widget=deform.widget.FormWidget(item_template="raw_description_mapping"))
Run Code Online (Sandbox Code Playgroud)
您可以使用 TALstructure表达式来转义 HTML。
例如raw_description_mapping.pt变形 2 的示例:
<tal:def tal:define="title title|field.title;
description description|field.description;
errormsg errormsg|field.errormsg;
item_template item_template|field.widget.item_template"
i18n:domain="deform">
<div class="panel panel-default" title="${description}">
<div class="panel-heading">${title}</div>
<div class="panel-body">
<div tal:condition="errormsg"
class="clearfix alert alert-message error">
<p i18n:translate="">
There was a problem with this section
</p>
<p>${errormsg}</p>
</div>
<div tal:condition="description">
${structure: description}
</div>
${field.start_mapping()}
<div tal:repeat="child field.children"
tal:replace="structure child.render_template(item_template)" >
</div>
${field.end_mapping()}
</div>
</div>
</tal:def>
Run Code Online (Sandbox Code Playgroud)
当使用 Pyramid 的配置器构建 WSGI 应用程序时,您还需要修改 Pyramid 应用程序以加载覆盖的 Deform 模板:
from pyramid_deform import configure_zpt_renderer
configure_zpt_renderer(["mypackage:templates/deform", "mypackage2.submodule:form/templates/deform"])
Run Code Online (Sandbox Code Playgroud)