new_topic |
if the topic doesn't already exist |
oops |
in oops script (see TWikiScripts) |
preview |
in preview script (see TWikiScripts) |
register |
in register script (see TWikiScripts) |
rename |
in rename script (see TWikiScripts) |
resetpasswd |
in resetpasswd script (see TWikiScripts) |
rss |
if this is an RSS skin rendering |
save |
in save script (see TWikiScripts) |
search |
in search script (see TWikiScripts) |
statistics |
in statistics script (see TWikiScripts) |
textareas_hijacked |
provided for use by editors that highjack textareas, and want to signal this fact. This is used by skins, for example, so they can suppress extra controls when textareas have been hijacked. |
upload |
in upload script (see TWikiScripts) |
view |
in view script (see TWikiScripts) |
viewfile |
in viewfile script (see TWikiScripts) |
rest |
in rest script (see TWikiScripts) |
registration_supported |
registration is supported by the current UserMapper |
registration_enabled |
set if {Register}{EnableNewUserRegistration} is on, and registrationis supported |
passwords_modifyable |
set if the password manager support changing the password / email |
In addition there is a context identifier for each enabled plugin; for example, if GallousTwistyPlugin is installed and enabled, then the context ID GallousTwistyPluginEnabled 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.
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.
Examples
1. TWiki variable defined or not
%IF{"defined 'WIKINAME'" then="WIKINAME is defined" else="WIKINAME is not defined"}%
2. Compare TWiki variable
You are %IF{ "$ WIKINAME='TWikiGuest' and not defined 'OPEN_DAY'" then="not" }% allowed to
%IF{ "context view" then="view" else="edit"}% this TWiki today.
3. URL parameter
%IF{ "defined 'search'" then="Search: $percntURLPARAM{search}$percnt" else="No search passed in"}%
4. Range test on URL parameter
url param t is %IF{ "0 < $ t and $ t < 1000" then="in" else="out of"}% range.
5. Text comparison of URL parameter
%IF{ "$'URLPARAM{scope}'='text'" then="Plain text search" }%
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 web
expands to:
You cannot change this topic.
You can change TestTopic.
You can change Sandbox web
9. Check topic existence
Topic Sandbox.TestTopic %IF{"istopic 'Sandbox.TestTopic'" then="exists" else="does not exist"}%
Web Sandbox.WebHome %IF{"isweb 'Sandbox'" then="exists" else="does not exist"}%
expands to:
Topic TestTopic does not exist
Web Sandbox 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
11. Conditional include
%IF{"'%USERNAME%' ingroup 'ExecutiveGroup'" then="$percntINCLUDE{ExecutiveReport}$percnt"}%
The ExecutiveReport topic is only included if the user is in the ExecutiveGroup.
12. Hide section of text conditionally using CSS display
<div style="display: %IF{"'%USERNAME%' ingroup 'TWikiAdminGroup'" then="block" else="none"}%">
* Conditional text enclosed in div tags here...
* ...can be as long as needed
</div>
Above text is only shown to users who are in the TWikiAdminGroup.
Related Topics: QuerySearch, VarIF, VarGET, VarSET, VarSEARCH, FormattedSearch, FormatTokens, SpreadSheetPlugin, TWikiScripts
-- Contributors: TWiki:Main.ArthurClemens , TWiki:Main.CrawfordCurrie , TWiki:Main.PeterThoeny , TWiki:Main.SopanShewale , TWiki:Main.SvenDowideit , TWiki:Main.WillNorris - 2012-08-07 |