Difference: IfStatements (1 vs. 12)

Revision 122012-10-03 - TWikiContributor

Line: 1 to 1
 

IF Statements

The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions.

Line: 35 to 35
 
can_login current environment supports login
changes in changes script (see TWikiScripts)
command_line the running script was run from the command line, and not from CGI
Added:
>
>
content_master with the current web, this site is the master of the federated sites (see ReadOnlyAndMirrorWebs)
content_slave with the current web, this site is a slave and another site in the federation is the master (see ReadOnlyAndMirrorWebs)
 
diff in rdiff script (see TWikiScripts)
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
Changed:
<
<
inactive if active links such as 'edit' and 'attach' should be disabled
>
>
inactive if active links such as 'edit' and 'attach' should be disabled; a read-only web puts all topics in this context (see ReadOnlyAndMirrorWebs)
 
login & logon in login / logon script (see TWikiScripts)
manage in manage script (see TWikiScripts)
Deleted:
<
<
mirror if this is a mirror
 
new_topic if the topic doesn't already exist
oops in oops script (see TWikiScripts)
preview in preview script (see TWikiScripts)

Revision 112012-08-07 - TWikiContributor

Line: 1 to 1
 

IF Statements

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"}%

Changed:
<
<
In the example above, if CONDITION evaluates to TRUE, then THEN will be included in the topic; otherwise ELSE will be included.
>
>
In the example above, if CONDITION evaluates to TRUE, then THEN will be shown in the topic; otherwise ELSE will be shown.
 
Changed:
<
<
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.
>
>
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 such as $percnt for % can be used in the THEN and ELSE parameters when you need to delay evaluation of (for example) a TWiki variable.
 
Changed:
<
<
The basic syntax of a condition is the same as the syntax used for queries, with operators =, !=, ~, <, >, <=, >=, NOT, AND, OR, (), and functions lc(), uc(), d2n(). In addition, the following special operators are supported:
>
>
The basic syntax of a condition is the same as the syntax used for queries, with operators =, !=, ~, <, >, <=, >=, NOT, AND, OR, (), and functions lc(), uc(), d2n().

In addition, the following special operators are supported:

 
context True if the current context is set (see below)
allows 'X' allows 'Y' is true if web/topic 'X' exists and allows access mode 'Y' for the current user. Web access rights are only checked if there is no topic called 'X'.
Line: 21 to 23
 
$ expands a URL parameter or TWikiVariable name. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
{X} expands to the value of the configuration variable {X} - for example, {ScriptUrlPath}
Changed:
<
<
Examples:
>
>
You can test if a configuration item is set or not, using conditions such as "{AntiSpam}{HideUserDetails}". It is not possible see the value of a configuration. Configuration items are defined in configure.

You can test if a context identifier is set or not, using conditions such as "context authenticated". Context identifier 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:

 
Changed:
<
<
1. TWiki variable defined or not
>
>
id context
absolute_urls Set if absolute URLs are required
attach in attach script (see TWikiScripts)
authenticated a user is authenticated
body_text when the body text is being processed in a view (useful in plugin handlers)
can_login current environment supports login
changes in changes script (see TWikiScripts)
command_line the running script was run from the command line, and not from CGI
diff in rdiff script (see TWikiScripts)
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
inactive if active links such as 'edit' and 'attach' should be disabled
login & logon in login / logon script (see TWikiScripts)
manage in manage script (see TWikiScripts)
mirror if this is a mirror
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"}%
Changed:
<
<
2. Compare TWiki variable
>
>
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.
Changed:
<
<
3. URL parameter
>
>
3. URL parameter
 
%IF{ "defined 'search'" then="Search: $percntURLPARAM{search}$percnt" else="No search passed in"}%
Changed:
<
<
4. Range test on URL parameter
>
>
4. Range test on URL parameter
 
url param t is %IF{ "0 < $ t and $ t < 1000" then="in" else="out of"}% range.
Changed:
<
<
5. Text comparison of URL parameter
>
>
5. Text comparison of URL parameter
 
%IF{ "$'URLPARAM{scope}'='text'" then="Plain text search" }% 
Changed:
<
<
6. Configuration item set or not
>
>
6. Configuration item set or not
 
%IF{ "{AntiSpam}{HideUserDetails}" then="User details are hidden" }%
Changed:
<
<
7. Plugin enabled test
>
>
7. Plugin enabled test
 
TablePlugin is %IF{ "context TablePluginEnabled" then="enabled" else="disabled" }%.
expands to:
TablePlugin is enabled.
Changed:
<
<
8. Check access permissions
>
>
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:
Changed:
<
<
You cannot change this topic. You can change TestTopic.
>
>
You cannot change this topic.
You can change TestTopic.
 You can change Sandbox web
Changed:
<
<
9. Check topic existance
>
>
9. Check topic existence
 
Topic Sandbox.TestTopic %IF{"istopic 'Sandbox.TestTopic'" then="exists" else="does not exist"}%
Changed:
<
<
Web TestTopic exists
>
>
Web Sandbox exists
  expands to:
Changed:
<
<
Topic TestTopic does not exist Web TestTopic exists
>
>
Topic TestTopic does not exist
Web Sandbox exists
 
Changed:
<
<
10. Group membership
>
>
10. Group membership
 
You %IF{"'%USERNAME%' ingroup 'TWikiAdminGroup'" then="are an admin" else="are a normal user"}% 
expands to:
You are a normal user
Changed:
<
<
11. Hide section of text conditionally using CSS visibility
>
>
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

 
Changed:
<
<
>
>
 
  • Conditional text enclosed in div tags here...
  • ...can be as long as needed
Above text is only shown to users who are in the TWikiAdminGroup.
Deleted:
<
<
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:

id context
absolute_urls Set if absolute URLs are required
attach in attach script (see TWikiScripts)
authenticated a user is authenticated
body_text when the body text is being processed in a view (useful in plugin handlers)
can_login current environment supports login
changes in changes script (see TWikiScripts)
command_line the running script was run from the command line, and not from CGI
diff in rdiff script (see TWikiScripts)
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
inactive if active links such as 'edit' and 'attach' should be disabled
login & logon in login / logon script (see TWikiScripts)
manage in manage script (see TWikiScripts)
mirror if this is a mirror
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 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.

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.

 Related Topics: QuerySearch, VarIF, VarGET, VarSET, VarSEARCH, FormattedSearch, FormatTokens, SpreadSheetPlugin, TWikiScripts
Changed:
<
<
-- Contributors: TWiki:Main.ArthurClemens, TWiki:Main.CrawfordCurrie, TWiki:Main.PeterThoeny, TWiki:Main.SopanShewale, TWiki:Main.SvenDowideit, TWiki:Main.WillNorris - 2011-04-04
>
>
-- Contributors: TWiki:Main.ArthurClemens, TWiki:Main.CrawfordCurrie, TWiki:Main.PeterThoeny, TWiki:Main.SopanShewale, TWiki:Main.SvenDowideit, TWiki:Main.WillNorris - 2012-08-07

Revision 102011-04-04 - TWikiContributor

Line: 1 to 1
 

IF Statements

The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions.

Line: 142 to 142
  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.
Changed:
<
<
Related Topics: QuerySearch, VarIF, VarSEARCH, FormattedSearch
>
>
Related Topics: QuerySearch, VarIF, VarGET, VarSET, VarSEARCH, FormattedSearch, FormatTokens, SpreadSheetPlugin, TWikiScripts
 
Changed:
<
<
-- Contributors: TWiki:Main/ArthurClemens, TWiki:Main/CrawfordCurrie, TWiki:Main/PeterThoeny, TWiki:Main/SopanShewale, TWiki:Main/SvenDowideit, TWiki:Main/WillNorris - 2010-04-09
>
>
-- Contributors: TWiki:Main.ArthurClemens, TWiki:Main.CrawfordCurrie, TWiki:Main.PeterThoeny, TWiki:Main.SopanShewale, TWiki:Main.SvenDowideit, TWiki:Main.WillNorris - 2011-04-04

Revision 92010-05-08 - TWikiContributor

Line: 1 to 1
 

IF Statements

The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions.

Line: 17 to 17
 
isweb isweb 'X' is true if web 'X' exists
ingroup 'X' ingroup 'Y' is true if user 'X' is in group 'Y'. 'X' can be a login name or a wikiname.
defined True if a preference variable or url parameter of this name is defined.
Added:
>
>
isempty True if a preference variable, url parameter or session variable of this name has an empty value. It is equivalent to the expression (defined(x) || $x='')
 
$ expands a URL parameter or TWikiVariable name. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
{X} expands to the value of the configuration variable {X} - for example, {ScriptUrlPath}
Line: 87 to 88
 expands to:
You are a normal user
Added:
>
>
11. Hide section of text conditionally using CSS visibility
<div style="visibility: %IF{"'%USERNAME%' ingroup 'TWikiAdminGroup'" then="visible" else="hidden"}%">
   * 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.
 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: 131 to 141
 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.

Added:
>
>
Related Topics: QuerySearch, VarIF, VarSEARCH, FormattedSearch

-- Contributors: TWiki:Main/ArthurClemens, TWiki:Main/CrawfordCurrie, TWiki:Main/PeterThoeny, TWiki:Main/SopanShewale, TWiki:Main/SvenDowideit, TWiki:Main/WillNorris - 2010-04-09

Revision 82009-06-05 - TWikiContributor

Line: 1 to 1
 

IF Statements

The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions.

Line: 9 to 9
  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.
Changed:
<
<
The basic syntax of a condition is the same as the syntax used for queries, with the addition of the following special operators:
>
>
The basic syntax of a condition is the same as the syntax used for queries, with operators =, !=, ~, <, >, <=, >=, NOT, AND, OR, (), and functions lc(), uc(), d2n(). In addition, the following special operators are supported:
 
Changed:
<
<
context True if the current context is set (see below)
allows 'X' allows 'Y' is true if web/topic 'X' exists and allows access mode 'Y' for the current user. Web access rights are only checked if there is no topic called 'X'.
istopic istopic 'X' is true if topic 'X' exists
isweb isweb 'X' is true if web 'X' exists
ingroup 'X' ingroup 'Y' is true if user 'X' is in group 'Y'. 'X' can be a login name or a wikiname.
defined True if a preference variable or url parameter of this name is defined.
$ expands a URL parameter or TWikiVariable name. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
{X} expands to the value of the configuration variable {X} - for example, {ScriptUrlPath}
>
>
context True if the current context is set (see below)
allows 'X' allows 'Y' is true if web/topic 'X' exists and allows access mode 'Y' for the current user. Web access rights are only checked if there is no topic called 'X'.
istopic istopic 'X' is true if topic 'X' exists
isweb isweb 'X' is true if web 'X' exists
ingroup 'X' ingroup 'Y' is true if user 'X' is in group 'Y'. 'X' can be a login name or a wikiname.
defined True if a preference variable or url parameter of this name is defined.
$ expands a URL parameter or TWikiVariable name. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
{X} expands to the value of the configuration variable {X} - for example, {ScriptUrlPath}
  Examples:
Line: 91 to 91
  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:
id context
Changed:
<
<
absolute_urls Set if absolute URLs are required
attach in attach script (see TWikiScripts)
authenticated a user is authenticated
body_text when the body text is being processed in a view (useful in plugin handlers)
can_login current environment supports login
changes in changes script (see TWikiScripts)
command_line the running script was run from the command line, and not from CGI
diff in rdiff script (see TWikiScripts)
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
inactive if active links such as 'edit' and 'attach' should be disabled
login & logon in login / logon script (see TWikiScripts)
manage in manage script (see TWikiScripts)
mirror if this is a mirror
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
>
>
absolute_urls Set if absolute URLs are required
attach in attach script (see TWikiScripts)
authenticated a user is authenticated
body_text when the body text is being processed in a view (useful in plugin handlers)
can_login current environment supports login
changes in changes script (see TWikiScripts)
command_line the running script was run from the command line, and not from CGI
diff in rdiff script (see TWikiScripts)
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
inactive if active links such as 'edit' and 'attach' should be disabled
login & logon in login / logon script (see TWikiScripts)
manage in manage script (see TWikiScripts)
mirror if this is a mirror
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 GallousBreeksPlugin is installed and enabled, then the context ID GallousBreeksPluginEnabled will be set. Other extensions may set additional context identifiers.

Revision 72007-07-07 - TWikiContributor

Line: 1 to 1
 

IF Statements

The %IF% construct gives TWiki the power to include content in topics based on the value of simple expressions.

Line: 15 to 15
 
allows 'X' allows 'Y' is true if web/topic 'X' exists and allows access mode 'Y' for the current user. Web access rights are only checked if there is no topic called 'X'.
istopic istopic 'X' is true if topic 'X' exists
isweb isweb 'X' is true if web 'X' exists
Changed:
<
<
ingroup 'X' ingroup 'Y' is true if user 'X' is in group 'Y'
>
>
ingroup 'X' ingroup 'Y' is true if user 'X' is in group 'Y'. 'X' can be a login name or a wikiname.
 
defined True if a preference variable or url parameter of this name is defined.
$ expands a URL parameter or TWikiVariable name. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
{X} expands to the value of the configuration variable {X} - for example, {ScriptUrlPath}
Line: 24 to 24
  1. TWiki variable defined or not
Changed:
<
<
WIKINAME is defined
>
>
WIKINAME is defined
 

2. Compare TWiki variable

Changed:
<
<
You are not allowed to
>
>
You are not allowed to
 edit this TWiki today.

3. URL parameter

Changed:
<
<
No search passed in
>
>
No search passed in
 

4. Range test on URL parameter

Line: 92 to 92
 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:
id context
absolute_urls Set if absolute URLs are required
Added:
>
>
attach in attach script (see TWikiScripts)
 
authenticated a user is authenticated
body_text when the body text is being processed in a view (useful in plugin handlers)
can_login current environment supports login
Line: 103 to 104
 
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
inactive if active links such as 'edit' and 'attach' should be disabled
Added:
>
>
login & logon in login / logon script (see TWikiScripts)
manage in manage script (see TWikiScripts)
 
mirror if this is a mirror
new_topic if the topic doesn't already exist
oops in oops script (see TWikiScripts)
preview in preview script (see TWikiScripts)
Added:
>
>
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)
Added:
>
>
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.
Added:
>
>
upload in upload script (see TWikiScripts)
 
view in view script (see TWikiScripts)
Added:
>
>
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

Revision 62007-07-07 - TWikiContributor

Line: 1 to 1
Changed:
<
<

IF Statements

>
>

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
Operators
and True if both sides are true
or True if one or other side is true
not negate the following expression
=, != String comparison
<, >, <=, >= Number comparison (there is no explicit numeric =)
 
context True if the current context is set (see below)
Added:
>
>
allows 'X' allows 'Y' is true if web/topic 'X' exists and allows access mode 'Y' for the current user. Web access rights are only checked if there is no topic called 'X'.
istopic istopic 'X' is true if topic 'X' exists
isweb isweb 'X' is true if web 'X' exists
ingroup 'X' ingroup 'Y' is true if user 'X' is in group 'Y'
 
defined True if a preference variable or url parameter of this name is defined.
Changed:
<
<
$ expands a URL parameter or TWikiVariable. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
examples:
>
>
$ expands a URL parameter or TWikiVariable name. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
{X} expands to the value of the configuration variable {X} - for example, {ScriptUrlPath}

Examples:

1. TWiki variable defined or not

 
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 web
expands 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
 
rss if this is an RSS skin rendering
save in save script (see TWikiScripts)
search in search script (see TWikiScripts)
Added:
>
>
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.
 
view in view script (see TWikiScripts)
rest in rest script (see TWikiScripts)
Added:
>
>
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 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.

Revision 52005-03-27 - TWikiContributor

Line: 1 to 1
 

IF Statements

Line: 64 to 64
 
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
Changed:
<
<
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
>
>
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
 
inactive if active links such as 'edit' and 'attach' should be disabled
mirror if this is a mirror
new_topic if the topic doesn't already exist

Revision 42005-03-27 - TWikiContributor

Line: 1 to 1
Added:
>
>

IF Statements

 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"}%

Line: 46 to 50
 
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:
id context

Revision 32006-06-25 - TWikiContributor

Line: 4 to 4
  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. The best way to use this feature is to define two TWikiVariables, one for the THEN case and the other for the ELSE case. For example:
<!--
   * Set LI = Fred is here!
   * Set LO = Fred is there!
-->
%IF{"context authenticated and defined WIKINAME and $ WIKINAME='FredBloggs'" then="%LI%" else="%LO%"}%
>
>
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:
Line: 22 to 15
 basexpr ::= atom | uop atom | atom bop basexpr ; uop ::= 'context' | 'defined' | '$' ; bop ::= '=' | '!=' | '>' | '<' | '>=' | '<=' ;
Changed:
<
<
atom ::= context identifier, TWiki variable name, single-quoted string
>
>
atom ::= context identifier, TWiki variable name, single-quoted string, or configuration item
 
Operators
and True if both sides are true
Line: 32 to 25
 
<, >, <=, >= Number comparison (there is no explicit numeric =)
context True if the current context is set (see below)
defined True if a preference variable or url parameter of this name is defined.
Changed:
<
<
$ expands a URL parameter or TWikiVariable. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The quoted string may not contain quotes (' or ").
>
>
$ expands a URL parameter or TWikiVariable. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The 'VARIABLE{value}' string may not contain quotes (' or ").
 examples:
Added:
>
>
TWiki variable defined or not
 WIKINAME is defined

You are not allowed to edit this TWiki today.

Added:
>
>
URL parameter
 No search passed in
Added:
>
>
Configuration item set or not User details are hidden
 url param t is out of range.
Added:
>
>
Text comparison
 
Deleted:
<
<
Given
  • Set OPEN_DAY = yes
this expands to:
 
Changed:
<
<
You are not allowed to edit this TWiki today.
>
>
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.
 
Changed:
<
<
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:
>
>
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:
 
id context
<-- -->
Sorted ascending
authenticated a user is authenticated
absolute_urls Set if absolute URLs are required
Line: 77 to 72
 
view in view script (see TWikiScripts)
rest in rest script (see TWikiScripts)
Changed:
<
<
In addition there is an identifier for each enabled plugin; for example, if GallousBreeksPlugin is installed and enabled, then the context ID GallousBreeksPluginEnabled will be set.
>
>
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.

Revision 12006-02-01 - TWikiContributor

Line: 1 to 1
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 best way to use this feature is to define two TWikiVariables, one for the THEN case and the other for the ELSE case. For example:

<!--
   * Set LI = Fred is here!
   * Set LO = Fred is there!
-->
%IF{"context authenticated and defined WIKINAME and $ WIKINAME='FredBloggs'" then="%LI%" else="%LO%"}%

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
Operators
and True if both sides are true
or True if one or other side is true
not negate the following expression
=, != String comparison
<, >, <=, >= Number comparison (there is no explicit numeric =)
context True if the current context is set (see below)
defined True if a preference variable or url parameter of this name is defined.
$ expands a URL parameter or TWikiVariable. Plugin handlers are not called. Built-in variables and user-defined preferences are supported. You can pass a limited subset of parameters to TWiki variables by enclosing the variable name in single quotes; for example, $ 'VARIABLE{value}'. The quoted string may not contain quotes (' or ").
examples:
%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.

%IF{ "defined search" then="Search: %URLPARAM{search}%" else="No search passed in"}%

url param t is %IF{ "0 < $ t and $ t < 1000" then="in" else="out of"}% range.

%IF{ "$'URLPARAM{scope}'='text'" then="Plain text search" }% 
Given
  • Set OPEN_DAY = yes
this expands to:

You are not allowed to edit this TWiki today.

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:

id context
absolute_urls Set if absolute URLs are required
authenticated a user is authenticated
body_text when the body text is being processed in a view (useful in plugin handlers)
can_login current environment supports login
changes in changes script (see TWikiScripts)
command_line the running script was run from the command line, and not from CGI
diff in rdiff script (see TWikiScripts)
edit in edit script (see TWikiScripts)
footer_text when the footer text is being processed in a view (useful in plugin handlers)
header_text when the header text is being processed in a view (useful in plugin handlers)
i18n_enabled when user interface I18N support is enabled (i.e., user can choose the language for UI)
inactive if active links such as 'edit' and 'attach' should be disabled
mirror if this is a mirror
new_topic if the topic doesn't already exist
oops in oops script (see TWikiScripts)
preview in preview script (see TWikiScripts)
rss if this is an RSS skin rendering
save in save script (see TWikiScripts)
search in search script (see TWikiScripts)
view in view script (see TWikiScripts)
rest in rest script (see TWikiScripts)

In addition there is an identifier for each enabled plugin; for example, if GallousBreeksPlugin is installed and enabled, then the context ID GallousBreeksPluginEnabled will be set.

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.

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.IfStatements.