我将此代码用于一个简单的下载链接(并且仅在“附件”字段具有值时出现 - 附件) - (工作正常):
<metal:field use-macro="python:here.widget('attachment', mode='view')" />
我也想提供一种不用下载直接查看文件的方法。我目前正在使用这个代码片段(工作正常):
<a tal:attributes="href string:${context/absolute_url}/attachment">View Attached File</a>
我想添加一个条件,即如果“附件”字段实际上有附件,则显示“查看”链接。但是,我无法让 tap:condition 工作。在测试这个我尝试了这些代码片段:
<span tal:condition="here/attachment">ATTACHMENT</span>
<span tal:condition="context/attachment">ATTACHMENT</span>
<span tal:condition="template/attachment">ATTACHMENT</span>
<span tal:condition="exists:template/attachment">ATTACHMENT</span>
<span tal:condition="string:${context/absolute_url}/attachment">ATTACHMENT</span>
<span tal:condition="python:here.widget('attachment', mode='view')">ATTACHMENT</span>
<span tal:condition="exists:python:here.widget('attachment', mode='view')">ATTACHMENT</span>
<span tal:define="file_exists2 exists:string:${context/absolute_url}/attachment" tal:condition="python:file_exists2">ATTACHMENT</span>
(无论附件是否存在,都会显示以上内容)
是否有一个简单的解决方案可以让 tal:condition 准确识别文件字段是否具有值并且在不存在附件时不显示并在存在时显示?