我有 2 个字段(字段 A 和字段 B)
我想要什么: - 如果 fieldA 包含某些内容,则不应显示 fieldB
我尝试什么:
<span tal:replace="here/getFieldA" />
<span tal:omit-tag="here/getFieldA" tal:replace="here/getFieldB" />
所以它不起作用
感谢您的帮助
我有 2 个字段(字段 A 和字段 B)
我想要什么: - 如果 fieldA 包含某些内容,则不应显示 fieldB
我尝试什么:
<span tal:replace="here/getFieldA" />
<span tal:omit-tag="here/getFieldA" tal:replace="here/getFieldB" />
所以它不起作用
感谢您的帮助
您正在寻找的是tal:condition
,可能与not:
andexists:
前缀结合使用:
<span tal:replace="here/getFieldA" />
<span tal:condition="not:exists:here/getFieldA" tal:replace="here/getFieldB" />
或者,您可以使用|
operator,它的作用类似于 if 运算符,测试第一个元素的存在。如果它不存在,它将使用下一个表达式,依此类推:
<span tal:replace="here/getFieldA | here/getFieldB" />
该tal:omit-tag
属性意味着非常不同的东西。如果它的表达式计算结果为True
,则从输出中省略该标记,并且仅省略该标记本身。最好用一个例子来说明这一点:
<span tal:omit-tag="">
<i>This part will be retained</i>
</span>
渲染该页面模板会导致:
<i>This part will be retained</i>
省略了周围的<span>
标签,但保留了内容。
这是根据评论对原始答案的改进:
<tal:block
tal:define="zone here/getZoneintervention;
thezone python:', '.join(zone);
dep here/getDepartements;
thedep python:', '.join(dep)">
<span tal:condition="zone" tal:replace="thezone" />
<span tal:condition="not:zone" tal:replace="thedep" />
</tal:block>
尝试
<span tal:condition="here/getFieldA" tal:replace="here/getFieldB" />
Zope 页面模板参考http://docs.zope.org/zope2/zope2book/AppendixC.html