Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Redirect to the first subnavigation entry

by Luc Muller last modified Jan 22, 2009 09:57 PM
How to procede automaticly to the first subnavigation entry?

Purpose

Sometimes, customers want the site navigation to procede automaticly to the first entry (i.e. Folder) of the subnavigation. Normaly you could do this by adding a Page Template "index_html" in the ZMI (Zope Management Interface) with a redirect to the first subfolder (context.REQUEST.response.redirect(...)). But normal plone editor cannot handle ZMI page templates.

This how-to describes a simple redirect procedure that can also be used by a plone content contributer/editor. 

Prerequisities

This is an adhoc customization in the ZMI. You only need to have a manager role so that you can customize plone skins in the portal_skins/custom folder.

Step by step

This are the steps you need to do:

  1. In the ZMI you have to create a python script "redirect_to_first_entry" and give it a readable title like  'Go to first element of the subnavigation'.
  2. In portal_types/Folder add "redirect_to_first_entry" a view method in  "Available view methods"

1. Creating the redirect python script

In the ZMI create a script (Python) "redirect_to_first_entry" in your portal_skins/custom folder:

folder_contents = context.getFolderContents()
for fc in folder_contents:
    if fc.portal_type == 'Folder' and not fc.exclude_from_nav :
        context.REQUEST.response.redirect(fc.getObject().absolute_url())
        break # yes, you have to!
return ''

Enter a human readable Title like "Go to first element of the subnavigation". Then change the Proxy Roles of the script to "Manager".

2. Add a view method to the Folder content type

In the ZMI go to the portal_types/Folder and add "redirect_to_first_entry" a view method in  "Available view methods":

Add view to available view methods

In Plone, the editors/contributors will see a new view action that allows them to redirect the user to the first entry of the subnavigation:

New view action

That's all. Hope it's useful. Feel free to comment this How-to.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.