TrailMenu
Questions answered by this recipe!! Question
Is it possible to build an expanding menu showing only those links related to the current page?
Answer
The trailmenu.phpΔ script allows an author to use a WikiTrail to build an editable, expanding navigation menu. It is based largely on the Cookbook-V1/Trail2Menu script authored by Niall Durham, but has been updated here to work with PmWiki 2.0.
Discussion
This script allows any WikiTrail to be used as the source for an expanding menu. For example, given a trail such as the following:
* [[Cookbook]] ** [[Skins]] *** GeminiSkin *** LinesSkin *** LightSkin *** LeanSkin ** [[Cookbook#markup | Markups]] *** MarkupExtended *** EnableHTML *** PostItNotes ** [[Cookbook#menus | Menus]] *** TreeMenu *** TrailMenu *** TrackingMenu *** ExpandingMenu ** [[Cookbook#uploads | Uploads]] *** UploadTypes *** AttachLinks * [[PmWiki]] ** [[PmWiki/DocumentationIndex]] ** [[Installation]]
the markup (:pagelist trail=Cookbook.TrailMenu fmt=trailmenu:)
will
display the trail as an expanding menu, with the items related to the current page highlighted. Thus:
(:pagelist trail=Cookbook.TrailMenu fmt=trailmenu:) |
Note that only those entries in the trail that are somehow related to the current page are displayed. ("Related" in this case means "direct descendents, direct ancestors, and ancestors' siblings".)
This is just a first cut at this recipe, improvements and comments are welcome.
Installation
To use trailmenu.phpΔ, simply download it, copy it into the cookbook/ directory, and add include_once('cookbook/trailmenu.php');
to a local customization file.
Next, create a trail containing the page links to be displayed in the menu, using deeper levels of bullets to indicate submenus.
Finally, use the markup (:pagelist trail=<TrailPage> fmt=trailmenu:)
to display the expanding menu in a page. This can be done in a sidebar or other location.
Notes and Comments
The original trailmenu does not work with pmwiki-2.2.x. Cause: In 2.2.x the 'parentnames'
element in $matches[]
and $PCache[]
is empty. My version jjs_trailmenu_3.phpΔ is only relying on $matches[]['parent']
. Tested with 2.1.17 and 2.2.0-beta18 and 2.2.0-beta19.
I wish, someone would create a new type of menu, combining the advantages of TrailMenu and ExpandingMenu. As TrailMenu builds its list of menu items from a WikiTrail, no external urls or using headings is allowed. TrailMenu has the disadvantage of relying on building its menu items from WikiGroups - why should one have to create Groups only to be able to use them in a menu. Now a perfect menu would be called with a directive like Expanding Menu and thus still be able to build its item list from a simple unordererd list like TrailMenu, but not relying on the disadvantages of a WikiTrail.
See Also
Contributors
- Pm, based on Niall Durham's Cookbook-V1.Trail2Menu script.
- Jjs, adaption for pmwiki-2.2.x based on trailmenu.php: jjs_trailmenu_3.phpΔ