Added: | |||||||||||||||||||||||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||||||||||||||||||||||
The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions.
%IF{"CONDITION" then="THEN" else="ELSE"}%
In the example above, if CONDITION evaluates to TRUE, then THEN will be included in the topic; otherwise ELSE will be included.
What can be included in the THEN and ELSE parameters is obviously limited by standard TWiki syntax for parameters.
The basic syntax of a condition is as follows:
expr ::= '(' expr ')' ; expr ::= andexpr | andexpr 'or' expr ; andexpr ::= notexpr | notexpr 'and' andexpr ; notexpr ::= basexpr | 'not' baseexpr ; basexpr ::= atom | uop atom | atom bop basexpr ; uop ::= 'context' | 'defined' | '$' ; bop ::= '=' | '!=' | '>' | '<' | '>=' | '<=' ; atom ::= context identifier, TWiki variable name, single-quoted string, or configuration item
TWiki variable defined or not %IF{"defined WIKINAME" then="WIKINAME is defined" else="WIKINAME is not defined"}% You are %IF{ "$ WIKINAME='TWikiGuest' and not defined OPEN_DAY" then="not" }% allowed to %IF{ "context view" then="view" else="edit"}% this TWiki today. URL parameter %IF{ "defined search" then="Search: %URLPARAM{search}%" else="No search passed in"}% Configuration item set or not %IF{ "{AntiSpam}{HideUserDetails}" then="User details are hidden" }% url param t is %IF{ "0 < $ t and $ t < 1000" then="in" else="out of"}% range. Text comparison %IF{ "$'URLPARAM{scope}'='text'" then="Plain text search" }% | |||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||
< < | Configuration items are defined in configure . You cannot see the value of a configuration item, you can only see if the item is set or not. | ||||||||||||||||||||||||||||||||||||||||||||
> > | Configuration items are defined in configure. You cannot see the value of a configuration item, you can only see if the item is set or not. | ||||||||||||||||||||||||||||||||||||||||||||
Context identifiers are used in TWiki to label various stages of the rendering process. They are especially useful for skin authors to find out where they are in the rendering process. The following context identifiers are available:
GallousBreeksPlugin is installed and enabled, then the context ID GallousBreeksPluginEnabled will be set. Other extensions may set additional context identifiers.
The %IF% statement is deliberately kept simple. In particular, note that there is no way to conditionally execute a Set statement. If you need more sophisticated control over formatting, then consider using the SpreadSheetPlugin. |