Skip to content. Skip to navigation

Jan Torbens homepage

You are here: Home public stuff Plone tag navigation
Document Actions

Plone tag navigation

by jtheuer last modified 2007-11-11 01:35

folderish navigation is often useless, because most pages have different places where they fit. A simple navigation by keywords (tags) is a soloution for small sites

Introduction

I just have a small site and I don't want to create a tree navigation, because it's useless and confuses the visitor.

The file (if it is a singe page) or the folder (for multi-page content) get's some keywords and from the keywords I generate a navigation list.

The sourcecode is really simple. first of all, there is a python script:

## Script (Python) "keywords"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE

keywords = list(context.portal_catalog.uniqueValuesFor('Subject'));
keywords.sort( lambda y,x: cmp(x,y) )
keywords.reverse()

hmap = []
url = ""
for keyword in keywords:
    results = context.portal_catalog(Subject=keyword)
    length = len(results)
    if length == 1:
        url = results[0].getURL
    if length > 0:
	hmap.append(
        	{'keyword': keyword,
         	'size': length,
         	'url': url}
         	)

return hmap

This script returns a hashmap with all the keywords, a counter and a url (if there is just one hit, you can directly link to the url.

A portlet shows the results:

<html xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      i18n:domain="plone">
<body>
<div metal:define-macro="portlet">

<dl class="portlet"
    id="portlet-keywords"
    tal:define="catalogSubjects here/keywords;">

    <dt class="portletHeader">
        <span i18n:translate="box_keywords">Keywords</span>
    </dt>


    <dd class="portletItem odd"
                            tal:repeat="subject catalogSubjects"

                            i18n:domain="plone-metadata"
                            i18n:translate=""
                            >
	<a	tal:define="link string:search?SearchableText=${subject/keyword}"
		tal:attributes="href link" tal:content="string:${subject/keyword} (${subject/size})">dummy</a>
    </dd>
</dl>
</div>
</body>

</html>

ToDo:

  • improve the css
  • add direct URL Link

Please add your suggestions under "comment". No registration required