Hide default view from getFolderContents results with TALES on Plone 4

二次信任 提交于 2019-12-25 00:20:46

问题


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

My site structure looks like the following:

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.

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

Any help is greatly appreciated, thanks.


回答1:


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

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

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

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.



来源:https://stackoverflow.com/questions/17925001/hide-default-view-from-getfoldercontents-results-with-tales-on-plone-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!