【问题标题】:Hide field without content for Dexterity content type为敏捷内容类型隐藏没有内容的字段
【发布时间】:2012-11-16 22:31:25
【问题描述】:

我用 Dexterity 创建了一个内容类型,添加一个项目后, 在首页,没有内容的字段仍然显示在详细信息页面中。

我想隐藏这些字段及其标题,我该怎么办?

【问题讨论】:

  • 您的意思是字段标签仍在为字段显示?
  • 是的,字段标签还在但没有内容

标签: plone dexterity


【解决方案1】:

您可以使用display form 自定义敏捷类型的视图。

这是一个z3c.form 表单,因此我们可以使用.updateWidgets() 方法将小部件的可用性动态设置为hide some of them

import z3c.form
from plone.directives import dexterity

class MyCustomView(dexterity.DisplayForm):
    grok.context(IMyContentType)
    grok.require('zope2.View')

    def updateWidgets(self):
        super(MyCustomView, self).updateWidgets()
        for widget in self.widgets.values():
            if not widget.value:
                widget.mode = z3c.form.interfaces.HIDDEN_MODE

【讨论】:

  • 我可以修改默认视图吗?它在哪里 ?我不知道如何创建自定义视图和哪个文件夹?
  • @BingquanBao:您要么必须自定义 item.pt 模板并查找那里是否有任何项目为空,要么您必须像我们在这里所做的那样子类化 DisplayForm(其中 是默认视图)。
  • 我想隐藏字段集,我该怎么做

猜你喜欢
  • 1970-01-01
  • 2012-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-04
相关资源
最近更新 更多