tal:文件附件字段的条件

时间:2016-02-26 14:24:37

标签: plone zpt tal

我正在使用此代码进行简单的下载链接(仅在“附件”字段具有值 - 附件时才会显示) - (正常工作):

<metal:field use-macro="python:here.widget('attachment', mode='view')" />

我还想提供一种直接查看文件而无需下载的方法。我目前正在使用此代码段(工作正常):

<a tal:attributes="href string:${context/absolute_url}/attachment">View Attached File</a>

我想添加一个条件,如果“附件”字段实际上有附件,则显示“查看”链接。但是,我无法获得点击:条件工作。在测试中我尝试了这些代码片段:

<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准确识别文件字段是否有值而不显示没有附件时显示?是什么时候显示?

1 个答案:

答案 0 :(得分:2)

您可以查看附件尺寸:

如果它是Archetype(在AT字段上调用getSize,它也可以公共遍历):

<span tal:condition="context/attachment/getSize">ATTACHMENT</span>

DX上的AFAIK不同,因为它是NamedBlobFile

<span tal:condition="context/attachment/get_size">ATTACHMENT</span>