IfGroup

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Goal

Implementing a group specific dynamic sidebar

Solution

group-dependent processing of links which are used in include-files or in main-sidebar

Discussion

Download attached php-script into your pmwiki's "local" directory.

Attach:IfGroup.php

Call from config.php using
include_once('local/IfGroup.php')

customize Sidebar by adding group specific lines:

Example:

 * [[ThisWiki ThisAndThat]]
 =ifnotgroup Main * Main/Homepage
 =ifgroup Main * %RED% Main/Homepage
 =ifnotgroup Topic1 * [[Topic1/HomePage TOPIC1:]]
 =ifgroup Topic1 * %RED% [[Topic1/HomePage TOPIC1:]]
 =ifgroup Topic1 ** Topic1/subject1 
 =ifgroup Topic1 ** Topic1/subject2 
 =ifnotgroup Topic2 * [[Topic2/HomePage TOPIC2:]]
 =ifgroup Topic2 * %RED% [[Topic2/HomePage TOPIC2:]]
 =ifgroup Topic2 ** Topic2/subject1 
 =ifgroup Topic2 ** Topic2/subject2 
 =ifgroup Topic1,Topic2 ** AllTopics/AnyPage 

(use the original lowercase wikistyles "red" instead of RED above)

The =ifgroup-markup must start in column 1 of a line. The markup is followed by a name of a group or a list of names of group separated by comma. The text following the groupname(s) will be blanked out if the group of the current displayed page is not within the specified list of groups, it will be processed if the name of the group of the current displayed page is included in the list.

The =ifnotgroup-markup works almost just the same, except that the text is processed if the group of the currently displayed page is not withing the specified grouplist (what did you exspect ? :-)

Markups can be mixed with "normal" link-lines

The result:

One level of Sidebar-entries will expand or collapse according to the group of the displayed pages.

e.g.

if the page Main.HomePage is displayed, the following entries will be displayed in the Sidebar:

 ThisAndThat
 Homepage           (of group main; in red color)
 TOPIC1:
 TOPIC2:

if a page Topic1.AnyPage is displayed, the following entries will be displayed in the Sidebar:

 ThisAndThat
 Homepage          (of group main; in black)
 TOPIC1            (in red color)
   subject1 
   subject2 
 AnyPage           (of group alltopics)

Also in the example above, the text of a active group (i.e. a group of a displayed page) will change the font-color to red.

Improvement:

I use an [[include:Groupname.SideBar]] within the Main.SideBar and within the Groupname.SideBar I place the =ifgroup-markups.

See Also

Trail2Menu by Niall Durham

History

2004-06-08 first implementation

Comments & Bugs

maybe this will become obsolete in version 2 when conditional markup will be available

Zet: I have modified the source for one reason: not displayed lines were returned as empty lines. The disadvantage is, that PmWiki interpretes this as a new paragraph beginning which produces gaps. My solution is to return %% since it is not displayed but doesn't count as an empty line → No gaps any more :)

Contributors

  • Thanks to Niall Durham whos Trail2Menu gave me that idea to this feature

Author

Knut Alboldt KAL pmwiki-2.3.32 -- Last modified by {{zet}}

from IP: 85.171.160.186 ip should be disabled by default for security reasons