Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

ExpandingMenu2

Summary: Provides markup to create an (automatically) expanding menu
Version: 2007-08-04
Prerequisites: pmwiki
Status:
Maintainer: pwuille
Categories: Menus, Layout

Goal

Create a nested expanding menu (eg. in a sidebar) that keeps the current page visible, and have control over what parts of the menu-tree are visible (expanded).

Features

It provides these features:

  • No JavaScript
  • Works with existing menu's
  • Automatically expands entries referring to the current page
  • Shows '+' and '-' to signify expandable and expanded items
  • Works in combination with Cookbook.GeminiSkin and Cookbook.FixFlowSkin, that put every link in the sidebar on a separate line
  • Provide markup to make other nodes visible/expanded.

Solution

Put emenu2.phpΔ in your cookbook directory (you may have to create it).

Add the following line to local/config.php:

    include_once("cookbook/emenu2.php");

Use

Surround a normal menu with (:emenu2:) and (:emenu2end:) directives. It is possible to have multiple such menu's visible at the same time, though you probably just want it for your SideBar.

Just like Cookbook.ExpandingMenu, it will add a <div class="emenu"> around the menu, so you can modify it with CSS.

By default, all nodes that have a link to the current page (and their parent nodes) will be expanded. It is however possible to additionally make other nodes visible and expanded, by putting

    (:emenu2expand Group.Page:)

in any page (not necessary the page containing the menu). See the example below. The effect of this directive can be reverted with (:emenu2collapse Group.Page:).

Example

(copy and paste to your page, it won't work here)

(:emenu2:)
* [[Main/Home Page]]
* [[Main/WikiSandbox]]
* [[PmWiki/Documentation Index | Documentation]]
** [[PmWiki/Installation | Download and Install]]
** [[PmWiki/FAQ]]
** [[PmWiki/Release Notes]]
** [[PmWiki/ChangeLog]]
* Submenu
** Submenu Item 1
** Submenu Item 2
(:emenu2end:)

(:emenu2:)

(:emenu2end:)

This would make the Documentation node expanded while you're visiting any of the pages beneath (Download and Install, FAQ, Release Notes or ChangeLog). You could, however, choose to make this node also expand when you're on the Home Page, by placing a (:emenu2expand PmWiki.Documentation Index:) on Main.HomePage. If you would want to have this node expanded while you're visiting any page in the PmWiki group, place that directive in the PmWiki.GroupHeader page, for example.

Notes

The code is somewhat based on that of Cookbook.ExpandingMenu by dstebila.

Release Notes

  • 2007-08-04
    • Initial release

Comments

pmwiki 2.2.10, xampp 1.7.3 (which includes Apache 2.2.14 and PHP 5.3.1), running under Windows XP and Windows 7 Home Edition

The split function on line 87? is deprecated and displays an error under Windows XP, however, under Windows 7 it sometimes outputs an error and most times it just seems to hang pmwiki. Replacing the split function directly with preg_split (as outlined in the php documentation here: http://php.net/manual/en/function.split.php) seems to have done the job.

Scott Farquharson 2010-02-05


The split function might also be replaced by expode().

See pmwiki change log: Version 2.2.13 (2010-02-21)

    * Replace deprecated in PHP 5.3 function split() with explode(). 

Peter Kiefel 2010-03-08


There seems to be an issue with version: 2007-08-04 in combination with PMWiki 2.2.0-beta65:
All spaces disappear in link captions of items that have children. E.g. [[Group.MyPage|My pretty caption]] would appear as Myprettycaption. List items without children do not show this behaviour.
Quick and dirty solution: Just removing script line 110 which says "remove spaces" worked for me - but I'm not sure what the side effects are, in general.\\ Irregular spaces in other parts could possible make the further replacements fail. Further suggestion (without actually understanding the script as a whole): Make RegExp in line 111 cope with any possible extra spaces \s* outside the parentheses and clean lmatch[1]-[4] from spaces afterwards. Frank Schweickert 2008-Jan-29

Besides, it would be nice if ExpandingMenu2 was compatible with Sitemapper that delivers a nested list e.g. for the sidebar and a line of breadcrumb navigation on every page.
Frank Schweickert 2008-Jan-28

See Also

Contributors

~pwuille

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on November 22, 2011, at 09:58 AM