在Plone 4上使用TALES隐藏getFolderContents结果中的默认视图 [英] Hide default view from getFolderContents results with TALES on Plone 4

查看:94
本文介绍了在Plone 4上使用TALES隐藏getFolderContents结果中的默认视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Plone 4网站上创建一个辅助导航栏,用于查看子文件夹的内容.

I am creating a secondary navigation bar on a Plone 4 site which looks at the contents of sub folders.

我的网站结构如下:

Plone Site
|
|--Folder1
   |--PageA
   |--PageB
|--Folder2
   |--PageC
   |--PageD

我的故事如下(我很欣赏这可能不是最优雅的代码):

My TALES is as follows (I appreciate that this is probably not the most elegant code):

<tal:subsections tal:define="isDocument python:getattr(context,'portal_type','') == 'Document';
                             isFolder python:getattr(context,'portal_type','') == 'Folder';
                             subitemsDocument python:context.aq_parent.aq_inner.getFolderContents(contentFilter={'portal_type':'Document'});
                             subitemsFolder python:context.getFolderContents(contentFilter={'portal_type':'Document'});
                             root_url context/portal_url;
                             front_url string:${root_url}/front-page;
                             current_url context/absolute_url;" tal:condition="context/portal_membership/isAnonymousUser">
  <ul id="subnav" tal:condition="isFolder">
    <tal:subtabsfolder tal:repeat="subitem subitemsFolder">
    <li tal:define="item_url subitem/getURL"
      tal:attributes="class python:current_url==item_url and 'selected' or 'plain'">
        <a tal:attributes="href subitem/getURL" tal:content="subitem/Title"/>
      </li>
    </tal:subtabsfolder>
  </ul>

  <ul id="subnav" tal:condition="isDocument">
    <tal:subtabsdocument tal:repeat="subitem subitemsDocument">
      <li tal:define="item_url subitem/getURL"
        tal:attributes="class python:current_url==item_url and 'selected' or 'plain'">
        <a tal:attributes="href subitem/getURL" tal:content="subitem/Title"
          tal:condition="python:front_url != current_url"/>
      </li>
    </tal:subtabsdocument>
  </ul>
</tal:subsections>

一切正常,我唯一的问题是我没有办法告诉模板忽略用作容器默认视图的项目.

Everything is working well, my only problem is that I do not have a way of telling the template to ignore items that have been used as the default view of a container.

我是否可以使用TALES条件来完成此任务?

Is there a TALES condition I can use to accomplish this?

非常感谢您的帮助.

推荐答案

您可以简单地使用Plone的上下文-utilities ,例如:

You can simply use Plone's context-utilities for that, like this:

tal:condition="not: subitem/@@plone_context_state/is_default_page

如果您很好奇,六尺起脚会提供一个很好的快速工作表,以获得更多的PDF变量引用.

In case you're courious Six Feet Up provides a nice quick-sheet, for more variable-references as a PDF.

顺便说一句:我将条件应用于list-element而不是link元素,以免呈现不必要的空list-element.

By the way: I'd apply the condition to the list-element instead of the link element, to not render an unnecessary empty list-element.

这篇关于在Plone 4上使用TALES隐藏getFolderContents结果中的默认视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆