如何设置TAL条件以检查文件类型并相应地在Plone 4.1中呈现模板

编程入门 行业动态 更新时间:2024-10-07 20:27:56
本文介绍了如何设置TAL条件以检查文件类型并相应地在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="www.xyz" 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="www.xyz" 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中呈现模板

本文发布于:2023-11-11 08:34:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件类型   如何设置   模板   条件   Plone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!