Abandoned. Replaced by IfPlugin in JSPWiki v2.5.106 and later. --DF, 26 Aug 07


Conditional Plugin#

This plugin allows to make parts of a page conditional to the existence of a page or variable or on the content of a page or variable. These variables can be external to the page from where the plugin is called. Also global WikiVariables can be validated.

Why?
Give more power to the use of page variables. This plugin should also allow to build more dynamic favorites (LeftMenu) pages or header and footer sections from a wiki-page instead of (current) hardwired jsp templates.

Could be a stupid idea ;-) --DF

How to use#

Basic use of the TEST plugin :

  [{brushed.jspwiki.conditional.TEST <some parameters> }]  renders "TRUE" when the test yields true

  [{TEST <some parameters> }]

  renders the body of the plugin when the test yields true
  this may contain a nested plugin call
  }]

You can test the presence of a page or variable :

  [{TEST page='Dinner' }]
  [{TEST name='eat' }]
  [{TEST page='Dinner' name='eat' }]
  [{TEST page='{$username}Favorites' }]  (supported since v2.3.99)

You can also test the content of a page or the value of a variable. Use regular expressions to match complex stuff.

  [{TEST name='eat' match='apple' }]
  [{TEST name='eat' match='apple*' }]       match 'apple' or 'apples' or ...
  [{TEST name='eat' match='apple|banana' }] match 'apple' or 'banana'

  [{TEST name='eat' except='pasta' }]       match anything except 'pasta'

  [{TEST name='eat' match='apple*' except='*pie' }]

  [{TEST name='{$loginstatus}' match='authenticated|asserted' }]

Parameters#

  • page : name of wiki page (optional - default is current page)
  • name : name of Wiki Variable (optional)
  • match : regular expression to match the page or variable against (optional) ; when matched the test result will yield TRUE
  • except : regular expression to match the page or variable against (optional) ; when not matched the test result will yield TRUE

Example#

Example of a dynamic left-menu

[{brushed.jspwiki.conditional.TEST name='context' match='edit|comment' 

[{IncludePage name='EditLeftMenu'}]
}]
[{brushed.jspwiki.conditional.TEST page='{$username}Favorites' 

%%collapsebox
! [MyFavorites|{$username}Favorites]
[{InsertPage page='{$username}Favorites' }]
%% 
}]
[{brushed.jspwiki.conditional.TEST name='pagename' match='Brushed.*' 

%%collapsebox
** ... some quicklinks to brushed pages
%%
}]

Backup - recall how to work with a wiki page variable#

See also WikiVariable

Variable handling is simple

  [{SET eat='apple' }]
  [{$eat }]
  • Set variable 'eat' here.
  • Read variable 'eat': apple


Is there a way to use this plugin with security? For instance I want some items on the Left menu to only show up if the users are in a certain group? This seems like a good use of this plugin with the new security stuff.

--Chris Rohr, 13-Jun-2006

No that I know of. The list of groups and roles a user is member of can not yet be retrieved via a variable. Could be useful as a new idea. --DF

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
java
TEST.java 4.9 kB 1 14-Apr-2006 22:12 Dirk Frederickx
jar
conditional.jar 2.5 kB 1 14-Apr-2006 22:11 Dirk Frederickx
« This page (revision-4) was last changed on 26-Aug-2007 12:24 by DirkFrederickx