Line: 1 to 1 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Changed: | |||||||||||||
< < |
| ||||||||||||
> > | IF Statements | ||||||||||||
The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions. | |||||||||||||
Line: 8 to 7 | |||||||||||||
In the example above, if CONDITION evaluates to TRUE, then THEN will be included in the topic; otherwise ELSE will be included. | |||||||||||||
Changed: | |||||||||||||
< < | What can be included in the THEN and ELSE parameters is obviously limited by standard TWiki syntax for parameters. | ||||||||||||
> > | Note that because of the way TWiki evaluates, then whatever is in the THEN and ELSE parameters will already have been expanded by the time the condition is actually evaluated. The standard FormatTokens can be used in the THEN and ELSE parameters when you need to delay evaluation of (for example) a TWiki variable. The basic syntax of a condition is the same as the syntax used for queries, with the addition of the following special operators: | ||||||||||||
Deleted: | |||||||||||||
< < | 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
| ||||||||||||
| |||||||||||||
Added: | |||||||||||||
> > |
| ||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Deleted: | |||||||||||||
< < | TWiki variable defined or not | ||||||||||||
WIKINAME is defined | |||||||||||||
Added: | |||||||||||||
> > | |||||||||||||
Added: | |||||||||||||
> > | 2. Compare TWiki variable | ||||||||||||
You are not allowed to edit this TWiki today. | |||||||||||||
Added: | |||||||||||||
> > | |||||||||||||
Changed: | |||||||||||||
< < | URL parameter No search passed in Configuration item set or not User details are hidden | ||||||||||||
> > | 3. URL parameter
%IF{ "defined search" then="Search: $percntURLPARAM{search}$percnt" else="No search passed in"}% | ||||||||||||
Added: | |||||||||||||
> > | 4. Range test on URL parameter | ||||||||||||
url param t is out of range. | |||||||||||||
Added: | |||||||||||||
> > | |||||||||||||
Changed: | |||||||||||||
< < | Text comparison | ||||||||||||
> > | 5. Text comparison of URL parameter | ||||||||||||
Added: | |||||||||||||
> > | 6. Configuration item set or not
%IF{ "{AntiSpam}{HideUserDetails}" then="User details are hidden" }%7. Plugin enabled test TablePlugin is %IF{ "context TablePluginEnabled" then="enabled" else="disabled" }%.expands to: TablePlugin is enabled. 8. Check access permissions You %IF{"'%TOPIC%' allows 'change'" then="can" else="cannot"}% change this topic. You %IF{"'Sandbox.TestTopic' allows 'change'" then="can" else="cannot"}% change Sandbox.TestTopic. You %IF{"'Sandbox' allows 'change'" then="can" else="cannot"}% change Sandbox webexpands to: You cannot change this topic. You can change TestTopic. You can change Sandbox web 9. Check topic existance Topic Sandbox.TestTopic %IF{"istopic 'Sandbox.TestTopic'" then="exists" else="does not exist"}% Web Sandbox.TestTopic %IF{"isweb 'Sandbox'" then="exists" else="does not exist"}%expands to: Topic TestTopic does not exist Web TestTopic exists 10. Group membership You %IF{"'%USERNAME%' ingroup 'TWikiAdminGroup'" then="are an admin" else="are a normal user"}%expands to: You are a normal user | ||||||||||||
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: | |||||||||||||
Line: 73 to 110 | |||||||||||||
| |||||||||||||
Added: | |||||||||||||
> > |
| ||||||||||||
| |||||||||||||
Added: | |||||||||||||
> > |
| ||||||||||||
In addition there is a context identifier for each enabled plugin; for example, if 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. | |||||||||||||
Added: | |||||||||||||
> > | Note also that while the query syntax can be used to access form fields, there are some contexts in which an IF statement may be used where there is no topic context, or the topic context is not what you expected. |