Plone中的TAL条件隐藏HTML,如果它是文档(页面)

时间:2014-03-24 19:47:53

标签: plone template-tal zpt

我尝试使用tal表达式修改我的/portal_view_customizations/zope.interface.interface-plone.belowcontenttitle.documentbyline模板,以便文档的作者和修改日期不会显示当前门户网站类型是文档(页面)。如果它显示的是时间敏感的新闻项目,而不是文档/页面,我不介意。

这是我失败的Plone TAL表达式:

<div class="documentByLine"
     id="plone-document-byline"
     i18n:domain="plone"
     tal:condition="view/show and not:python:here.portal_type == 'Document'"> 
...

我也尝试过:

<div class="documentByLine"
     id="plone-document-byline"
     i18n:domain="plone"
     tal:condition="view/show and not:context/portal_type='Document'">

但仍然没有运气。回溯非常神秘,与TAL表达无关。但是,如果我摆脱了portal_type的条件,那么它再次起作用。任何想法都表示赞赏。手册会很好,但是我看过官方的手册,但他们没有提到这一点。

1 个答案:

答案 0 :(得分:2)

TAL的基础TALES是TAL使用的表达引擎,它不支持在一个表达式中混合表达式类型。它的syntax只允许指定一个表达式类型(默认为&#39;路径&#39;,如果省略,顺便说一句),因为没有提供分隔符(就像用于链接多个TAL的分号) - 一个元素中的陈述,例如)。

但是,不是混合三种表达式类型,而是可以使用一个python-expression,请尝试:

python: view.show and context.portal_type()!='Document'

<强>更新

如果您通过portal_view_customizations(&#39; TTW&#39;)自定义了Plone的默认模板,则现在无法访问restricted python-methods,&#39;为什么view/show会抛出错误。

它返回site-properties的allowAnonymousViewAbout - 属性,你也可以自己查看这个条件,你的表达式如下:

tal:define="name user/getUserName" 
tal:condition="python:test(name!='Anonymous User') and context.portal_type()!='Document';

快速的替代方案

使用CSS:

body.userrole-anonymous .documentByLine {display:none}
body:not(.template-document_view) .documentByLine {display:block}

这将呈现隐藏的元素,但它有助于原型设计等,或者快速修正&#39; (没有管理员等)。

相关问题