Summary: A Conditional Markup extension for PmWiki 2.x
Version: 20150217
Status: Stable
Prerequisites: pmwiki-2.1.beta33+
Maintainer: Dfaure
License: see terms in php file
Categories: Markup

Question answered by this recipe

I've found the ConditionalMarkup very powerful, but how do I handle more complex expressions involving string/number comparisons, pattern/pagename matching and/or several simultaneous conditions ?


Download extendcond.phpΔ, save it in the cookbook directory and add: include_once("$FarmD/cookbook/extendcond.php"); to your local configuration file.


The recipe script provides extras conditional markup verbs to handle regular boolean expressions and string/number comparisons.

String/Number comparisons

(:if eq VALUE1 VALUE2:)
(:if lt VALUE1 VALUE2:)
(:if le VALUE1 VALUE2:)
(:if gt VALUE1 VALUE2:)
(:if ge VALUE1 VALUE2:)
All these conditions compares two string/number values.

They may be either literal or variable values as in: (:if eq {$Author} Dfaure:)

Strings containing spaces may be enclosed between quotes.

eqsynonym for equal
ltless than
leless or equal than
gtgreater than
gegreater or equal than

All these condition verbs may be given with a trailing 'i' as in eqi, lti,... to do case-insensitives comparisons.

Pattern/Pagename matching

(:if regmatch REG_EXPRESSION VALUE:) True if the value matches the regular expression.
(:if matchname NAME_SPEC PAGENAME:) True if the given pagename/groupname match the wildcard placeholder specification.
(:if matchgroup GROUP_SPEC GROUPNAME:)

Boolean expressions

The boolean expressions extension defined by this recipe has been integrated into PmWiki core since v2.1.0beta33: The previously related recipe code part has been dropped.

Following forms are equivalents:


The "expr" condition take sub-conditions expressions combined with regular PHP boolean operators and brackets, and let PHP evaluate them to get the result.

A and BAndTRUE if both A and B are TRUE.
A or BOrTRUE if either A or B is TRUE.
A xor BXorTRUE if either A or B is TRUE, but not both.
! ANotTRUE if A is not TRUE.
A && BAndTRUE if both A and B are TRUE.
A || BOrTRUE if either A or B is TRUE.

With A and B being either regular conditions (see ConditionalMarkup) or bracketed boolean expressions of regular conditions.


  • Spaces around operators and brackets are required.
  • No specific feedback is given for syntaxic errors or unbalanced brackets.


With the code below:

(:if expr auth admin || auth attr || auth edit :)
[[Logout -> {$Name}?action=logout]] %green%{$Author}%%

you get a logout link followed by the current author name available only when authentified with higher than 'read' right.


See Also


Release Notes

  • 2005-02-28 Initial proof-of-concept release.
  • 2005-04-20 Updated to a more reliable/usual syntax.
  • 2005-05-03 Following a Pm's suggestion, spaces around operators are now mandatory to allow exclamation marks and parenthesis in regular conditions terms.
  • 2005-09-14 Removed extraneous undocumented "Properties" features to its own recipe.
  • 2005-09-19 Fixed a security issue (thanks to Pm and M.Fick). Added alternates syntax forms and equality condition.
  • 2006-03-02 Revamped equality condition to more general string/numbers comparisons. Updated licensing terms.
  • 2006-06-20 Added partial string matches with regular expressions.
  • 2006-10-28 Added RecipeInfo data. Added pagename wildcard matching.
  • 2015-02-17 Dropped obsolete code interfering with PHP5.5 compatibility


Some boolean tables:

ABCA or ( B and C )A and ( ! B or C )
AB( A && ! B ) || ( ! A && B )A xor B


See discussion at ConditionalExtensions-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.