如何设置TAL条件以检查文件类型并相应地在Plone 4.1中呈现模板 [英] How to set TAL condition to check the file type and accordingly render the template in Plone 4.1
问题描述
如何使用tal条件检查文件类型并在Plone 4.1中呈现模板
How to use the tal condition to check the file type and render the template in Plone 4.1
我的文件预览模板渲染取决于文件扩展名.如果文件扩展名是"pdf",我希望使用这样的格式:(刚开始使用TAL,TALES和METAL)
My file preview template rendering depends upon the file extension. If file extension is 'pdf', I wish to use something like this:(just started working with TAL, TALES, METAL)
<tal:define="file_nm global string:${here/absolute_url}"
<tal:condition="file_nm.slice[-3:] = 'pdf'">
<embed width="100%" height="100%" name="plug-in" tal:attributes="src string:${here/absolute_url}#"
draggable="false" onselectstart="false" />
其他使用:(用于"pdf"以外的文件)
else use :(for files other than 'pdf')
<IFRAME src="http://www.xyz.com"
tal:attributes="src string:${here/absolute_url}/rfpreview"
ondragstart="false" onselectstart="false"
width="100%" height="400" scrolling="auto" frameborder="0"></IFRAME>
有人可以指导我了解有关自定义视图的完整自定义代码段:atreal.richfile.preview.interfaces.ipreview-atreal.richfile.preview.viewlet
Can someone guide me on the complete custom code snippet for custom view :atreal.richfile.preview.interfaces.ipreview-atreal.richfile.preview.viewlet
推荐答案
TAL语句是现有标签上的属性.您可以 引入带有tal:
名称空间前缀的伪元素,但是像define
和condition
这样的语句仍需要表示为属性.
TAL statements are attributes on existing tags. You can introduce dummy elements with the tal:
namespace prefix, but the statements like define
and condition
need to expressed as attributes still.
此外,默认的TALES表达式类型是路径表达式,但是您想使用python表达式.很好,但是您需要使用python:
前缀指定它们.
Also, the default TALES expression type is path expressions, but you want to use python expressions. That's fine, but you need to specify them as such with the python:
prefix.
最后但并非最不重要的一点是,除非绝对必要,否则不要使用global
,这确实很少.定义的名称位于定义它们的XML元素的范围内,而不必位于这些名称之外.
Last but not least, don't use global
unless you absolutely have to, which is really rarely. Defined names live in the scope of the XML element they are defined on, and don't need to live on outside of these.
这是我表达逻辑的方式:
Here is how I'd express the logic:
<tal:block define="ispdf python:here.absolute_url().endswith('.pdf')">
<embed width="100%" height="100%" name="plug-in"
tal:condition="ispdf"
tal:attributes="src string:${here/absolute_url}#"
draggable="false" onselectstart="false" />
<iframe src="http://www.xyz.com"
tal:condition="not:ispdf"
tal:attributes="src string:${here/absolute_url}/rfpreview"
ondragstart="false" onselectstart="false"
width="100%" height="400" scrolling="auto" frameborder="0"></iframe>
</tal:block>
这引入了一个新的<tal:block>
元素来定义ispdf
布尔变量,该变量由python表达式确定.然后,根据该元素的True
或False
值,通过每个元素上的tal:condition
属性打开或关闭这两个变体.
This introduces a new <tal:block>
element to define the ispdf
boolean variable, determined by a python expression. Then the two variants are switched on or off by the tal:condition
attributes on each element based on that value being True
or False
.
这篇关于如何设置TAL条件以检查文件类型并相应地在Plone 4.1中呈现模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!