version=pmwiki-2.1.11 ordered=1 urlencoded=1
agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4
author=StirlingWestrup
csum=Added mention of nested expressions.
host=216.138.194.169
name=PmWiki.ConditionalMarkup
rev=82
targets=PmWiki.DocumentationIndex
text=%25define=indent block margin-left=2em%25%0a%25audience%25 authors, admins (advanced)%0a!! Using the [=(:if:)=] Directive%0aThe [@(:if:)@] directive allows portions of a page to be included or %0aexcluded from processing.  The generic form of the [@(:if:)@] directive is%0a%0a%25indent%25&nbsp;[@(:if cond param:) body (:ifend:)@]%0a%0awhere "cond" names a condition to be tested (described below), and "param" %0ais a parameter or other argument to the condition.%0a%0aThe built-in conditions include:%0a%0a(:table border=0 cellpadding=0 cellspacing=0 valign=top:)%0a(:cellnr rowspan=250:)%0a%25indent%25&nbsp;%0a(:cell:)[@(:if name PAGENAME:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current page is named "[@PAGENAME@]"%0a(:cellnr:)[@(:if group GROUPNAME:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current group is named "[@GROUPNAME@]"%0a(:cellnr:)[@(:if auth LEVEL PAGENAME:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)viewer is authorized at "[@LEVEL@]" where [@LEVEL@] can be: [@read@], [@edit@], [@upload@], [@attr@] or [@admin@]; [@PAGENAME@] is optional.%0a(:cellnr:)[@(:if authid:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current viewer is authenticated%0a(:cellnr:)[@(:if true:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)always include text%0a(:cellnr:)[@(:if false:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)always exclude text (same as a comment)%0a(:cellnr:)[@(:if attachments:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current page has attachments%0a(:cellnr:)[@(:if date DATE:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if current date is [@DATE@]%0a(:cellnr:)[@(:if date DATE..:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if current date is [@DATE@] or later (unlimited)%0a(:cellnr:)[@(:if date DATE1..DATE2:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if current date is in range [@DATE1@] to [@DATE2@] (inclusive)%0a(:cellnr colspan=3 align=center:)%0a%25green center%25[-''dates are in the format yyyy-mm-dd or yyyymmdd''-]%0a%0a(:cellnr:)[@(:if enabled VAR:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if PHP VAR is true%0a(:cellnr:)[@(:if enabled AuthPw:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if user has entered any password during the current browser session.%0a(:cellnr:)[@(:if equal STRING1 STRING2:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if [@STRING1@] equals [@STRING2@]%0a(:cellnr:)[@(:if match REG_EXPRESSION:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if current page name matches the regular expression%0a(:cellnr:)[@(:if exists PAGENAME:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)true if the page ''pagename'' exists%0a(:tableend:)%0a%0aNegated forms of conditions also work:%0a%0a(:table border=0 cellpadding=0 cellspacing=0 valign=top:)%0a(:cellnr rowspan=250:)%0a%25indent%25&nbsp;%0a(:cell:)[@(:if !attachments:)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)this page has no attachments%0a(:cellnr colspan=3:)&nbsp;%0a(:cellnr:)[@(:if ! name PAGENAME:)@]%0a(:cell rowspan=3:)%0a(:cell rowspan=3 valign=middle:)current page is NOT named "[@PAGENAME@]"%0a(:cellnr:)[@(:if name -PAGENAME :)@]%0a(:cell:)%0a(:cellnr:)[@(:if name !PAGENAME :)@]%0a(:tableend:)%0a%0aAny [@(:if:)@] automatically terminates the previous one, thus markup can be %0aeasily cased (and are not nested):%0a%0a%25indent%25&nbsp;[@(:if enabled AuthPw:)* You're logged in@]\\%0a%25indent%25&nbsp;[@(:if auth read:)* You can read@]\\%0a%25indent%25&nbsp;[@(:if auth edit:)* You can edit@]\\%0a%25indent%25&nbsp;[@(:if auth upload:)* You can upload@]\\%0a%25indent%25&nbsp;[@(:ifend:)@]%0a%0a!!! Using wildcard placeholders(:if false:)%25green%25[-(new for pmwiki 2.1.beta21)-]:(:if:)%0a%0aThe character [@*@] can be used as a wildcard to represent any character, %0azero, one or multiple times.\\%0aThe character [@?@] can be used as a wildcard to represent any character %0aexactly one time.\\%0aWildcard characters ([@*@] and [@?@]) can be used with the ''name'' and ''group'' conditional markups, thus:%0a%0a(:table border=0 cellpadding=0 cellspacing=0 valign=top:)%0a(:cellnr rowspan=250:)%0a%25indent%25&nbsp;%0a(:cell:)[@(:if name PmCal.2005* :)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current page is in group PmCal and begins with 2005%0a(:cellnr:)[@(:if group PmWiki* :)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current page is in group PmWiki or a group beginning with Pmwiki%0a(:cellnr:)[@(:if name Profiles.*,-Profiles.Profiles :)@]%0a(:cell:)&nbsp;-&nbsp;%0a(:cell:)current page is in group [@Profiles@] but not [@Profiles.Profiles@]%0a(:tableend:)%0a%0a!!! Combining conditions%0aConditions (as previously defined) may be combined into more complex %0aconditional expressions using one of these three equivalent forms:%0a%0a%25indent%25&nbsp;[@(:if expr EXPRESSION :)@]\\%0a%25indent%25&nbsp;[@(:if [ EXPRESSION ] :)@]\\%0a%25indent%25&nbsp;[@(:if ( EXPRESSION ) :)@]%0a%0aConditions are combined into expressions with boolean operators and %0abrackets. In the next table, A and B are either regular conditions or %0a(round-)bracketed sub-expressions of regular conditions:%0a%0a>>indent%3c%3c%0a|| border=1 cellpadding=2 cellspacing=0%0a||! Expression ||! Operator ||! Result ||%0a|| [@A and B@] || And ||TRUE if both A and B are TRUE.||%0a|| [@A or B@] || Or ||TRUE if either A or B is TRUE.||%0a|| [@A xor B@] || Xor ||TRUE if either A or B is TRUE, but not both.||%0a|| [@! A@] || Not ||TRUE if A is not TRUE.||%0a|| [@A && B@] || And ||TRUE if both A and B are TRUE.||%0a|| [@A || B@] || Or ||TRUE if either A or B is TRUE.||%0a>>%3c%3c%0a%0aNota:%0a* %25red%25 Spaces around operators and brackets are required.%0a* No specific feedback is given for syntaxic errors or unbalanced brackets.%0a* Use round brackets (not square) for nested expressions.%0a%0aThus, the following is a valid way of building an expression that shows the following contents only when the user is either the administrator, or is logged in and the time is later than the given date:%0a%0a->[@(:if [ auth admin || ( authid && date 2006-06-01 ) ] :)@]%0a%0aNesting with square brackets will silently fail to work as expected:%0a%0a->[@(:if [ auth admin || [ authid && date 2006-06-01 ] ] :) @]&nbsp;&nbsp;&nbsp;%25red%25NOTE: Doesn't Work!%0a%0aA common use of these complex tests are for expressions like:%0a%0a->[@(:if expr auth admin || auth attr || auth edit :)@]%0a->[@[[Logout -> {$Name}?action=logout]]@]%0a->[@(:if:)@]%0a%0awhich provides you a ''logout'' link ''only'' when authentified with rights higher than 'read'.%0a%0a%25audience%25 admins (advanced)%0a!! Creating new conditions%0a%0aSee [[Cookbook:ConditionalMarkupSamples]].%0a%0a%25trail%25%3c%3c|[[DocumentationIndex]]|>>%0a%0a
time=1151730012
