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

----
[{TableOfContents }]
!! 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|DirkFrederickx]


! 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|EditFindAndReplaceHelp] 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. [{SET eat='apple' }]
* Read variable 'eat': [{$eat }]



----

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|DirkFrederickx]