首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >允许在Deform表单描述字段中使用原始HTML

允许在Deform表单描述字段中使用原始HTML
EN

Stack Overflow用户
提问于 2015-09-17 18:30:39
回答 1查看 312关注 0票数 5

如何在渲染时阻止Deform转义字段标题或描述中的HTML?我目前最好的解决方案是用我需要的东西搜索/替换返回的呈现HTML字符串。

Deform默认情况下会将所有HTML字符转义为HTML实体,我想在其中一个字段描述中添加一个标记。

EN

回答 1

Stack Overflow用户

发布于 2015-09-17 19:36:57

复制默认的小部件模板,并修改它以允许未转义的条目。

描述由mapping.pt放置。不能覆盖每个小部件-表单中所有项目的映射模板都是相同的。您可以通过将item_template传递给小部件容器(表单、表单节)来覆盖映射。未测试示例:

代码语言:javascript
复制
  # No .pt extension for the template!
  schema = CSRFSchema(widget=deform.widget.FormWidget(item_template="raw_description_mapping"))

You can use TAL structure expression to unescape HTML

例如,Deform 2的raw_description_mapping.pt示例:

代码语言:javascript
复制
<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>

在使用Pyramid的配置器构建WSGI应用程序时,您还需要修改您的Pyramid应用程序以加载覆盖的变形模板:

代码语言:javascript
复制
    from pyramid_deform import configure_zpt_renderer

    configure_zpt_renderer(["mypackage:templates/deform", "mypackage2.submodule:form/templates/deform"])
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32628161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档