navi plugin

navi plugin by Andreas Gohr
Build a navigation menu from a list

Last updated on 2009-02-03. Provides Syntax.
Compatible with DokuWiki 2009-12-25+.

Conflicts with yalist!
Similar to indexmenu.

Tagged with menu, navigation.

This plugin allows you to create a nested navigation menu based on a list defined in a Wiki page. Lower navigation levels are shown or hidden dependent on the current page. It is intended for the use in the sidebar of a template supporting one (tested on Arctic). A notable feature is that it allows you to create hierarchical menus without the need of a hierarchical namespace structure.

Download and Install

Use the download link above to either manually download the plugin or install it through the plugin manager.

Changes

Usage

In the page defining the sidebar in your template add the following syntax:

{{navi>navigationmenu}}

where navigationmenu is any other page containing an unordered list of page links — this page we call the “control page”.

Notes:

  • The created menu is completely independent of any namespace structure. The hierarchy is created by the list nesting only. Exception: when the ?ns option is used (see below)
  • The navigation menu page should contain exactly one unordered list, other content will be ignored
  • The list items should only contain links, any other syntax will be ignored
  • Each page linked in the list should occur only once

Control Page Example

The following would create a menu with 4 top level entries: “Welcome”, “Products”, “Service” and “Wiki Syntax”. When you are on the “Products” page, the sub entries “Foomatic 2000” and “Foomatic 2010” are visible.

  * [[start|Welcome]]
  * [[Products]]
    * [[Foomatic 2000]]
    * [[Foomatic 2010]]
  * [[Service]]
    * [[about|About Foo Inc.]]
    * [[Contact]]
  * [[syntax|Wiki Syntax]]

This allows you to create hierarchical menus without the need of a hierarchical namespace structure.

Making use of Namespaces

Sometimes the navi plugin is used to create collapsible, editable navigation even though content is structured into nested namespaces. But since the plugin knows nothing about those namespaces by default it will collapse completely as soon as a page is opened that is not defined in the control page.

By adding ?ns to the navi plugin syntax you can make the plugin to be clever about namespaces: When it is called on a page that is not mentioned on the control page, it will have a look at the namespace of the page. It then checks if a startpage for the namespace is to be found in the control page. If it is, it will be used as the current open branch, if not it is checked if there is any other page in the same namespace on the controlpage. If found it's used. This is repeated for each higher namespace until the top is reached or a matching page.

User Comments

Live demo?

A link to a demo of this plugin would be useful. — Fernando 2009/03/03 11:07

Or perhaps some screenshots. — Josef 2009/04/18 15:00

More Info

I need more help implementing this. I have the arctic template which was tested. How do I get this to work. I don't know where the sidebar definition is.

To the anonymous user above:
Using the arctic template you have options to use several different types of sidebar. Let's say you want to use a namespace sidebar (which you should enable first in the config manager), and you are in namespace XYZ. Create page XYZ:sidebar, with this content:
  Look at my navigation links!
  {{navi>XYZ:navigationmenu}}
Then create page XYZ:navigationmenu, and fill it with an unordered list of navigation links. (BTW, note that the page name “navigationmenu” is a more or less arbitrary choice.)
Now visit some page in namespace XYZ, you should see the sidebar with your navigation menu.
You may also want to highlight the menu item associated to the current page, using a bit of CSS, e.g.
  div.sidebar_box .curid a { background-color: #666 !important; color: #FFF !important; }
I've just described a setup that worked for my wiki; it's not necessarily an example of “best practice” though. — Fernando 2009/03/17 14:55

Root namespaces

I have created page :navigation with

{{navi>:menu?ns}}

and :menu page with hierarchical structure like this:

  * [[:page1]]
    * [[:page1.1]]
  * [[:page2]]
  * [[:page3]]

I have also some page in page1 namespace like :page1:some_page. When I get to the :page1:some_page now the navi plugin generates links like

<a href="http://site.tld/page1/page2"></a>

instead of

<a href="http://site.tld/page2"></a>

that I thought would navi provide.

Am I doing something wrong or is it not possible to achieve such a behaviour?

I have found solution for my problem though I had to modify syntax.php of the navi plugin. I commented out these lines:
// we need the top ID for the renderer
/* $oldid = $ID;
$ID = $INFO['id']; */

Ctibor Brančík 2009/03/31 21:48

I have found that the links are generated relative to the current page. My fix was to add the root namespace (around line 189) like this

            $R->internallink(':'.$info['page'],$info['title']);

Is this stupid?

Souheil Inati 2009/04/22

In the page defining the sidebar in your template …

This is difficult to understand to me. Is this a wiki page or some template file residing in the operating system?

I like it in principle, but ...

Nice for one thing: hiding namespaces in the main menu for which a user does not have permissions. Where I got into trouble was that I have a » start « page in the root namespace. I also have a » start « page in namespace » ns1 «. Now, when my » navigation « file says:

  * [[:start]]\\
  * [[:ns1:start]]\\

Both items behave as expected when I am in the root namespace. However, when I'm in » ns1 «, item-1 when clicked takes me to » :ns1:start «. Yes, the documentation says that's what it does, but when I first parsed it, I did not get the significance of that detail. So, in effect, this feature is not really usable in the main menu without using the » sidebar « file to have a “hard” pointer to » :start « in the » sidebar « before or after the {{navi>navigation}} in the » sidebar «. A side effect is an unwanted line break between the two unordered lists.

You use a unordered list in combination with linebreaks, which isn't needed. Solution: remove the linebreaks. — Klap-in 2010/01/23 02:08

File » sidebar «:

__**Navigation**__\\
  * [[:start|Home]]\\
{{navi>navigation}}\\

File » navigation «:

  * [[:ns1:start|The ns1 namespace starts here]]\\

Of course, a usable circumvention is to rename the » start « file in each namespace to the name of the namespace in which it exists. This does, however, suggest unique filenames regardless of namespace. – Not good.
2-May-2009 – rexkarz00 – [at] – yahoo

The fix given by Souheil Inati worked for me :
in lib/plugins/navi/syntax.php, replace (line 187)
  $R->internallink($info['page'],$info['title']);


with

  $R->internallink(':'.$info['page'],$info['title']);


François Picot 2009/06/01

Implemented in indexmenu

The functionality provided by this plugin is now also available in indexmenu. See http://www.ceng.metu.edu.tr/~ahmet/Mektep/index.php?id=mektep:plugins&serveplugin_help=indexmenu. — Ahmet Sacan 2009/09/20

marking top-level menu items as active?

It is easy to modify the custom-CSS file to automatically highlight the currently active menu-entry/list-item, like so:

  • List Item1
  • List Item2
    • Active Sublist Item
  • List Item3

However, I did not find a way to also highlight the menu-entries above the currently active menu. I think it would be very nice, if the navi-plugin would markup the parents of an active list item, so they could be highlighted as well (helping the visitor to understand, where he/she's at; like so:,

  • List Item1
  • List Item2
    • Active Sublist Item
  • List Item3

paull 2010/01/30 17:44

Bug with ListItem level

First of all thanks for nice plugin. However it has one bug. When the plugin renders list it creates list with wrong levels. I added this CSS to the Arctic template I am using:

div.dokuwiki div.sidebar_box LI:before { content: attr(class) ':';}

Now browser will display class attribute for all <LI> elements in sidebar. From this I found that first item in any <UL> sublist of level >= 2 has first item of previous level. Look at these screenshots:

Without CSS modification Wit tweaked CSS Wit tweaked CSS - everything is OK

To correct this, replace line #173

$R->listitem_open($lvl);

with the following one

$R->listitem_open($lvl+1);

so that for loop should be like this:

                // more than one run is bad nesting!
                for($lvl; $lvl < $info['lvl']; $lvl++){
                    $R->listu_open();
                    $R->listitem_open($lvl+1); //For correct list item class!
                    $open = true;
                }

Andriy 2010/03/16 19:15

Hierarchical highlight of navigation menu

To all, who need hierarchical highlight of navigation menu like Paull asked above, here is my solution.

1. Fix the bug with ListItem level, see above. Without this the javascript code below will not work properly.

2. Add the following CSS to template you are using (I'm using Arctic Template so I modified arctic_design.css):

div.dokuwiki div.sidebar_box div.li_current {font-weight: bold; text-decoration: underline;}

3. Add this JavaScript to main.php somewhere at the end (between </body> and </html>, for example)

<script type="text/javascript">
var Candidates = document.getElementsByTagName('span');
if (Candidates.length>0){
 for (i=0;i<Candidates.length;i++){
  if(Candidates[i].className == 'current'){
   CurrentSpan = Candidates[i];
   while (true){
    if (CurrentSpan.tagName == 'LI' ) { CurrentSpan.firstChild.className = 'li_current'; }
    if (CurrentSpan.className == 'level1' ) { break; }
    CurrentSpan = CurrentSpan.parentNode;
   }
   break;
  }
 }
}
</script>

Andriy 2010/03/16 19:20

 
plugin/navi.txt · Last modified: 2010/03/16 18:13 by 194.44.164.133
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate