How to hide an item from the navigation tree even if it is the current item
Purpose
This how-to is about some steps one can follow to hide certain items from ever showing up in the navigation tree.
Normally, one can go to properties of a piece of content and select Exclude from navigation to hide an item from appearing the in the navigation tree. However, when the item is the current item, that is, the item you are viewing now, it will still be shown in the navigation tree. This how-to illustrates a trick on how hide it even if it is the current item.
Why would someone want to hide certain items from showing up in the navigation tree? One reason is that you have content in a folder that is very different from the rest of the site and you want to have a special navigation strategy for them. For example, you have some visitor-oriented links that you want to separate from the structural links of the site (an example would the the links under "Information For" and the ones under "Information About" at the Stanford School of Engineering website)
Prerequisities
This how-to applies to Plone 2.5.2 and Zope 2.9.6 and it should good for all the Plone 2.5.x versions.
Step by step
- Let's say you have a folder named visitors and you do not want it and any of the content inside it showing up in the navigation tree.
- First of all, install the Plone product CustomNav (make sure you get 1.1+) and add it to your Plone site.
- Hide the folder visitors by going to properties and check the checkbox for Exclude from navigation and save. This step will hide the folder from showing up in the navigation tree normally but it will still show up if the current item is a piece of content within the folder.
- Go to ZMI and look for the page template portlet_custom_navigation_example in /portal_skins/customnav_portlets.
- Create a new page template based on the code in portlet_custom_navigation_example in your custom folder. Call the new page template portlet_alt_navigation.
- Edit the code of portlet_alt_navigation:
- Make the <div> tag at the top
<div metal:define-macro="portlet" i18n:domain="plone" tal:omit-tag="" tal:define="view context/@@navigation_view; root view/navigationRoot;"> -
Define basePath as the root of the site (that is, nothing after string:)
tal:define="basePath string:
- Make the title of the navigation box point to the site map of the site (default behavior of the original navigation tree)
<a href="#" class="tile" tal:attributes="href string:${portal_url}${basePath}/sitemap">navigation</a> - If you want the Home link to appear in your new navigation tree (default behavior of the original navigation tree), you need to add the following code under <ul class="portletNavigationTree navTreeLevel0"> (this is why you need to define view and root above in step 1)
<li class="navTreeItem" tal:condition="view/includeTop"> <tal:block define="typeClass string:visualIcon contenttype-${view/rootTypeName}; selectedClass python:test(path('view/isPortalOrDefaultChild'), 'navTreeCurrentItem', ''); "> <div class="visualIcon contenttype-plone-site" tal:attributes="class typeClass"> <a class="visualIconPadding" tal:attributes="href root/absolute_url; title portal/Description; class string:$selectedClass visualIconPadding;"> <span tal:omit-tag="" tal:condition="python:root == portal" i18n:translate="tabs_home">Home</span> <span tal:condition="python:root != portal" tal:replace="root/Title">Home</span> </a> </div> </tal:block> </li> - Now, add currentItem=None to your call to the customNavtree external method
<li tal:define="tree python:context.customNavtree(basePath=basePath, currentItem=None)
- Go to the folder visitors in your ZMI, click on the Properties tab
- Add a new property called left_slots with type lines
- For the value of left_slots, replace the original navigation portlet with the new portlet you just create: here/portlet_alt_navigation/macros/portlet
- Because of Zope's acquisition mechanism, all the content inside visitors will now use the new navigation portlet and it won't be highlighted in the navigation tree because of currentItem=None we set above
You may now ask: how we are going to access the content inside visitors if it is never shown in the navigation tree? By using CustomNav, you can create another navigation tree with basePath equal to string:/visitors. In this case you will have an extra independent navigation tree that just shows the content within visitors.
Further information
CustomNav: http://plone.org/products/customnav

