Log In
or
Register
TWiki Web
Users
Groups
Index
Search
Changes
Notifications
Statistics
Preferences
User Reference
ATasteOfTWiki
TextFormattingRules
TWikiVariables
FormattedSearch
TWikiDocGraphics
TWikiSkinBrowser
InstalledPlugins
Admin Maintenance
Reference Manual
AdminToolsCategory
InterWikis
ManagingWebs
TWikiSiteTools
TWikiPreferences
WebPreferences
Categories
Admin Documentation
Admin Tools
Developer Doc
User Documentation
User Tools
Webs
Afp
Afp0304
Afp0405
Afp0506
Afp0607
AfpBadCopy
AfscheidDoaitseSwierstra
Alexey
Aop
Apa
Apa0506
ArieMiddelkoop
Atze
B3so
Bachelor
Bookmarks
Buildfarm
CSMaster
Cco
Center
DTP
Dos
Ehc
Eifl
Esdx
ExamCommitteeSciences
ExamenCommissie
FOO
FP
FPDag2012
FPLC
Fosa
GP
GamesAndVirtualWorlds
Gavw
GenericProgramming
Gnp
Gw
HUT
Hage
HaskellResources
Helium
HerzieningBachelorInformatica
Hpc
Hpc02
IFIP21
IFL
IFL2010
IPA2013
IS
ISS
Ipt
Ist
MSO
MTCH
Main
Martin
Master
Intern
MasterProgramComputingScience
Merijn
MethodEngineering
Mso1011
No
OWMT
OacBaICA
OacBaIKU
OacMastersCs
Odc
ProgrammingEnvironments
PrologJCU
Proxima
klad
Pt
Pt03
Pt04
Pv
Sandbox
SemanticWeb
Sgc
Sgc04
Spm
Stc
StrictnessAnalysisJFC
Students
Swa
Swe
Swe03
Swe04
Swe05
Swe0607
Sws
TC
TFP2014
TS
TS0506
TWiki
Tbpa
Techno
TechnologyForTeaching
Toetsing
TomVanDerWeide
Top
Trace
Trash
Ts
UHC
USCS
USCS2009
USCS2010
USCS2011
Uhc
Vermaas
Visser
VrouwenEnICT
WP
WebFunctions
WiskundeBDeficientie
WorkingConferenceProgramTransformation
Xagp
ZZZ
Center
Home
Courses
People
Projects
Page
Edit Page
Rename Page
Attach File
Printable
Wiki Source
More ...
Web
Recent Changes
Notify Service
News
?
Page Index
Search
More ...
Wiki
About TWiki
Text Formatting
Registration
Change Password
Reset Password
Users
Groups
Log In
or
Register
If Statements
TWiki
---+ =IF= Statements The =%<nop>IF%= construct gives TWiki the power to include content in topics based on the value of simple expressions. =%<nop>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: <verbatim> 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 </verbatim> | *Operators* || | and | True if both sides are true | | or | True if one or other side is true | | not | negate the following expression | | <nop>=, !<nop>= | 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 [[TWikiVariables][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: <verbatim> 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" }% </verbatim> *Configuration items* are defined in [[%SCRIPTURLPATH{"configure"}%][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 [[TWikiSkins][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 <nop>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 a context identifier for each enabled plugin; for example, if =Gallous<nop>BreeksPlugin= is installed *and enabled*, then the context ID =Gallous<nop>BreeksPluginEnabled= will be set. Other extensions may set additional context identifiers. The =%<nop>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.