Syntax

%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.

Note that because of the way Foswiki evaluates, 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 macro.

True if a preference setting, 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 macro name. Plugin handlers are not called. You can pass a limited subset of parameters to macros by enclosing the parameter string in single quotes; for example, $'MACRO{value}'. The 'MACRO{value}' string may not contain quotes: ' or ".

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.

Context identifiers

%IF{"context CONTEXT" then="THEN" else="ELSE"}%

Context identifiers are used in Foswiki 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:

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.
JQueryPlugin sets a context for each enabled JQuery plugin, for example: LiveQueryEnabled, UI::DialogEnabled. Other extensions may set additional context identifiers.

Query syntax

%IF{"QUERY" then="THEN" else="ELSE"}%

Examples

Display the value of a form field if the topic has form field "Summary":

%FORMFIELD{
"%IF{
"'%TOPIC%'/Summary"
then="Summary"
}%"
}%

Note that while a query search 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 want. In these cases you can use the / operator to indicate the name of the topic: