mirror of
https://gitlab.com/siarp/siarp.de.git
synced 2026-08-07 19:18:17 +00:00
194 lines
15 KiB
HTML
194 lines
15 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
|
|
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 1.0" dir="ltr">
|
|
|
|
|
|
<!-- Mirrored from siarp.de/node/201 by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 08 Dec 2019 12:00:36 GMT -->
|
|
<head profile="http://www.w3.org/1999/xhtml/vocab">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="Generator" content="Drupal 7 (http://drupal.org)" />
|
|
|
|
|
|
<title>Plone 3: How to really exclude from navigation | siarp.de</title>
|
|
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_xE-rWrJf-fncB6ztZfd2huxqgxu4WO-qwma6Xer30m4.css" media="all" />
|
|
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_NdVgz6YKifxQUEsW5xls_zI7Pn2F7E5U5Wb29zcu3vo.css" media="all" />
|
|
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_OAqUol8y_hmU_lCucLyaRX-a1G627sWWbvG_VG1GKnE.css" media="all" />
|
|
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_xPIRNNJGw8EiKyuE5b-xAtWWTQ8U1_huTr4xL09Dq2A.css" media="all" />
|
|
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_k3snrbsthqot7V7ccRZHS9OkCZkwBv4adtNieIVlbEU.css" media="print" />
|
|
|
|
<script type="text/javascript" src="../../sites/siarp.de/files/js/js_qikmINIYTWe4jcTUn8cKiMr8bmSDiZB9LQqvceZ6wlM.js"></script>
|
|
<script type="text/javascript" src="../../sites/siarp.de/files/js/js_VaTlC5jNdxR2e4HzWsuiV1jhDftON6pzITcrr9IQmXA.js"></script>
|
|
<script type="text/javascript">
|
|
<!--//--><![CDATA[//><!--
|
|
jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"garland","theme_token":"pXbi0wp3tE_GO9paH9IVP9xkIuJNZx_eZ5XDXZd6-aw","js":{"misc\/jquery.js":1,"misc\/jquery-extend-3.4.0.js":1,"misc\/jquery.once.js":1,"misc\/drupal.js":1,"misc\/tableheader.js":1},"css":{"modules\/system\/system.base.css":1,"modules\/system\/system.menus.css":1,"modules\/system\/system.messages.css":1,"modules\/system\/system.theme.css":1,"modules\/comment\/comment.css":1,"modules\/field\/theme\/field.css":1,"modules\/node\/node.css":1,"modules\/user\/user.css":1,"sites\/all\/modules\/views\/css\/views.css":1,"sites\/all\/modules\/ctools\/css\/ctools.css":1,"public:\/\/geshi\/geshifilter-languages.css":1,"sites\/siarp.de\/modules\/geshifilter\/geshifilter.css":1,"themes\/garland\/style.css":1,"themes\/garland\/print.css":1,"themes\/garland\/fix-ie.css":1}}});
|
|
//--><!]]>
|
|
</script>
|
|
</head>
|
|
<body class="html not-front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-201 node-type-story fluid-width" >
|
|
<div id="skip-link">
|
|
<a href="#main-content" class="element-invisible element-focusable">Skip to main content</a>
|
|
</div>
|
|
|
|
<div id="wrapper">
|
|
<div id="container" class="clearfix">
|
|
|
|
<div id="header">
|
|
<div id="logo-floater">
|
|
<div id="branding"><strong><a href="../../">
|
|
<span>siarp.de</span> </a></strong></div>
|
|
</div>
|
|
|
|
</div> <!-- /#header -->
|
|
|
|
|
|
<div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
|
|
<h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="../../">Home</a></div> <a id="main-content"></a>
|
|
<div id="tabs-wrapper" class="clearfix"> <h1 class="with-tabs">Plone 3: How to really exclude from navigation</h1>
|
|
</div> <div class="clearfix">
|
|
<div class="region region-content">
|
|
<div id="block-system-main" class="block block-system clearfix">
|
|
|
|
|
|
<div class="content">
|
|
<div id="node-201" class="node node-story node-promoted">
|
|
|
|
|
|
|
|
<span class="submitted">21. August 2009 - 0:49 — <span class="username">Martin</span></span>
|
|
|
|
<div class="content clearfix">
|
|
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Plone has multiple ways of excluding a content object from the navigation:</p>
|
|
|
|
<ul>
|
|
<li>In the edit tab of the object under settings check "Exclude from navigation"</li>
|
|
<li>Add the ID to <span class="geshifilter"><code class="text geshifilter-text">idsNotToList</code></span> in <span class="geshifilter"><code class="text geshifilter-text">portal_properties/navtree_properties</code></span></li>
|
|
<li>Add the meta type to <span class="geshifilter"><code class="text geshifilter-text">metaTypesNotToList</code></span> in <span class="geshifilter"><code class="text geshifilter-text">portal_properties/navtree_properties</code></span></li>
|
|
</ul>
|
|
|
|
<p>This works fine but the item is still displayed in the navigation tree if it's the current item (the one you're currently viewing). This may have a reason (usability?) but it is not what I want in some cases. If you put a link to the terms and conditions in the footer, for example, you don't want this to show up in the navigation tree when you click on it.</p>
|
|
|
|
<p>To solve this you can override the template for the navigation portlet (it may also work for the portal tabs) and add the conditions for the exclusion there.</p>
|
|
|
|
<h2>Overriding the navigation portlet template</h2>
|
|
|
|
<p>Copy the files <span class="geshifilter"><code class="text geshifilter-text">navigation.pt</code></span> and <span class="geshifilter"><code class="text geshifilter-text">navigation_recurse.pt</code></span> to your package. Then create a file <span class="geshifilter"><code class="text geshifilter-text">navigation.py</code></span> with the following content to create your own renderer based the original overriding the templates:</p>
|
|
|
|
<div class="geshifilter"><div class="python geshifilter-python"><span class="kw1">from</span> plone.<span class="me1">app</span>.<span class="me1">portlets</span>.<span class="me1">portlets</span>.<span class="me1">navigation</span> <span class="kw1">import</span> Renderer<br />
|
|
<span class="kw1">from</span> Products.<span class="me1">Five</span>.<span class="me1">browser</span>.<span class="me1">pagetemplatefile</span> <span class="kw1">import</span> ViewPageTemplateFile<br />
|
|
<br />
|
|
<span class="kw1">class</span> MyRenderer<span class="br0">(</span>Renderer<span class="br0">)</span>:<br />
|
|
_template <span class="sy0">=</span> ViewPageTemplateFile<span class="br0">(</span><span class="st0">'navigation.pt'</span><span class="br0">)</span><br />
|
|
recurse <span class="sy0">=</span> ViewPageTemplateFile<span class="br0">(</span><span class="st0">'navigation_recurse.pt'</span><span class="br0">)</span></div></div>
|
|
|
|
<p>Next, you have to register the class in the <span class="geshifilter"><code class="text geshifilter-text">configure.zcml</code></span> to override the original renderer.</p>
|
|
|
|
<div class="geshifilter"><div class="xml geshifilter-xml"><span class="sc3"><span class="re1"><configure</span></span><br />
|
|
<span class="sc3"> <span class="re0">xmlns:plone</span>=<span class="st0">"http://namespaces.plone.org/plone"</span><span class="re2">></span></span><br />
|
|
<br />
|
|
<span class="sc3"><span class="re1"><include</span> <span class="re0">package</span>=<span class="st0">"plone.app.portlets"</span> <span class="re2">/></span></span><br />
|
|
<br />
|
|
<span class="sc3"><span class="re1"><plone:portletRenderer</span></span><br />
|
|
<span class="sc3"> <span class="re0">portlet</span>=<span class="st0">"plone.app.portlets.portlets.navigation.INavigationPortlet"</span></span><br />
|
|
<span class="sc3"> <span class="re0">class</span>=<span class="st0">".navigation.MyRenderer"</span></span><br />
|
|
<span class="sc3"> <span class="re2">/></span></span><br />
|
|
<br />
|
|
<span class="sc3"><span class="re1"></configure<span class="re2">></span></span></span></div></div>
|
|
|
|
<p>(Note: If you want to do this for one theme only, put the code into your theme package and add <span class="geshifilter"><code class="text geshifilter-text">layer="..browser.interfaces.IThemeSpecific"</code></span> to the <span class="geshifilter"><code class="text geshifilter-text"><plone:portletRenderer></code></span> element.)</p>
|
|
|
|
<p>If you restart Zope now, you are using your own class and templates but there's no difference, yet.</p>
|
|
|
|
<h2>Adding conditions to really exclude from navigation</h2>
|
|
|
|
<p>First we expose the <span class="geshifilter"><code class="text geshifilter-text">idsNotToList</code></span> and <span class="geshifilter"><code class="text geshifilter-text">metaTypesNotToList</code></span> properties to the templates by adding the following to <span class="geshifilter"><code class="text geshifilter-text">navigation.py</code></span>:</p>
|
|
|
|
<div class="geshifilter"><div class="python geshifilter-python">...<br />
|
|
<span class="kw1">from</span> plone.<span class="me1">memoize</span>.<span class="me1">instance</span> <span class="kw1">import</span> memoize<br />
|
|
<span class="kw1">from</span> Products.<span class="me1">CMFCore</span>.<span class="me1">utils</span> <span class="kw1">import</span> getToolByName<br />
|
|
<br />
|
|
<span class="kw1">class</span> MyRenderer<span class="br0">(</span>Renderer<span class="br0">)</span>:<br />
|
|
...<br />
|
|
<span class="sy0">@</span>memoize<br />
|
|
<span class="kw1">def</span> getMetaTypesNotToList<span class="br0">(</span><span class="kw2">self</span><span class="br0">)</span>:<br />
|
|
context <span class="sy0">=</span> <span class="kw2">self</span>.<span class="me1">context</span><br />
|
|
portal_properties <span class="sy0">=</span> getToolByName<span class="br0">(</span>context<span class="sy0">,</span> <span class="st0">'portal_properties'</span><span class="br0">)</span><br />
|
|
navtree_properties <span class="sy0">=</span> <span class="kw2">getattr</span><span class="br0">(</span>portal_properties<span class="sy0">,</span> <span class="st0">'navtree_properties'</span><span class="br0">)</span><br />
|
|
<span class="kw1">return</span> <span class="kw2">list</span><span class="br0">(</span>navtree_properties.<span class="me1">metaTypesNotToList</span><span class="br0">)</span><br />
|
|
<br />
|
|
<span class="sy0">@</span>memoize<br />
|
|
<span class="kw1">def</span> getIdsNotToList<span class="br0">(</span><span class="kw2">self</span><span class="br0">)</span>:<br />
|
|
context <span class="sy0">=</span> <span class="kw2">self</span>.<span class="me1">context</span><br />
|
|
portal_properties <span class="sy0">=</span> getToolByName<span class="br0">(</span>context<span class="sy0">,</span> <span class="st0">'portal_properties'</span><span class="br0">)</span><br />
|
|
navtree_properties <span class="sy0">=</span> <span class="kw2">getattr</span><span class="br0">(</span>portal_properties<span class="sy0">,</span> <span class="st0">'navtree_properties'</span><span class="br0">)</span><br />
|
|
<span class="kw1">return</span> <span class="kw2">list</span><span class="br0">(</span>navtree_properties.<span class="me1">idsNotToList</span><span class="br0">)</span></div></div>
|
|
|
|
<p>Now we can finally add the conditions to the template so the item is not displayed in the navigation portlet any more. In <span class="geshifilter"><code class="text geshifilter-text">navigation_recurse.pt</code></span> change</p>
|
|
|
|
<div class="geshifilter"><div class="text geshifilter-text">tal:condition="python:bottomLevel &lt;= 0 or level &lt;= bottomLevel"</div></div>
|
|
|
|
<p>to</p>
|
|
|
|
<div class="geshifilter"><div class="text geshifilter-text">tal:condition="python:(not node['item'].id in view.getIdsNotToList()) and (node['portal_type'] not in view.getMetaTypesNotToList()) and (not node['item'].exclude_from_nav) and (bottomLevel &lt;= 0 or level &lt;= bottomLevel)"</div></div>
|
|
|
|
<p>That's it!</p>
|
|
|
|
<p>References:</p>
|
|
|
|
<ul>
|
|
<li>http://plone.org/documentation/how-to/override-the-portlets-in-plone-3.0/</li>
|
|
<li>http://plone.org/support/region/de#nabble-td1643152%7Ca1643152</li>
|
|
</ul>
|
|
</div></div></div><div class="field field-name-upload field-type-file field-label-hidden"><div class="field-items"><div class="field-item even"><table class="sticky-enabled">
|
|
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
|
|
<tbody>
|
|
<tr class="odd"><td><span class="file"><img class="file-icon" alt="Binary Data" title="application/octet-stream" src="../../modules/file/icons/application-octet-stream.png" /> <a href="../../sites/siarp.de/files/plonetutorial.excludefromnav-1.0dev-py2.4/" type="application/octet-stream; length=5979" title="plonetutorial.excludefromnav-1.0dev-py2.4.egg">plonetutorial.excludefromnav-1.0dev-py2.4.egg</a></span></td><td>5.84 KB</td> </tr>
|
|
<tr class="even"><td><span class="file"><img class="file-icon" alt="Image icon" title="image/png" src="../../modules/file/icons/image-x-generic.png" /> <a href="../../sites/siarp.de/files/Bild%2010.png" type="image/png; length=173790" title="Bild 10.png">Bild 10.png</a></span></td><td>169.72 KB</td> </tr>
|
|
<tr class="odd"><td><span class="file"><img class="file-icon" alt="Image icon" title="image/png" src="../../modules/file/icons/image-x-generic.png" /> <a href="../../sites/siarp.de/files/Bild%2011.png" type="image/png; length=173490" title="Bild 11.png">Bild 11.png</a></span></td><td>169.42 KB</td> </tr>
|
|
<tr class="even"><td><span class="file"><img class="file-icon" alt="Image icon" title="image/png" src="../../modules/file/icons/image-x-generic.png" /> <a href="../../sites/siarp.de/files/Bild%2013.png" type="image/png; length=150155" title="Bild 13.png">Bild 13.png</a></span></td><td>146.64 KB</td> </tr>
|
|
</tbody>
|
|
</table>
|
|
</div></div></div> </div>
|
|
|
|
<div class="clearfix">
|
|
<div class="links"><ul class="links inline"><li class="comment_forbidden first last"></li>
|
|
</ul></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="region region-footer">
|
|
<div id="block-block-3" class="block block-block clearfix">
|
|
|
|
|
|
<div class="content">
|
|
<p>Alle Rechte liegen bei siarp.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->
|
|
|
|
<div id="sidebar-second" class="sidebar">
|
|
<div class="region region-sidebar-second">
|
|
<div id="block-menu-menu-autoren" class="block block-menu clearfix">
|
|
|
|
<h2 class="title">Written by</h2>
|
|
|
|
<div class="content">
|
|
<ul class="menu"><li class="first leaf"><a href="../../blog/2/">Martin</a></li>
|
|
<li class="last leaf"><a href="../../blog/3/">Tilman</a></li>
|
|
</ul> </div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div> <!-- /#container -->
|
|
</div> <!-- /#wrapper -->
|
|
</body>
|
|
|
|
<!-- Mirrored from siarp.de/node/201 by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 08 Dec 2019 12:01:12 GMT -->
|
|
</html>
|