Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Added: | ||||||||
> > | ||||||||
TWiki Variables | ||||||||
Changed: | ||||||||
< < | Special text strings expand on the fly to display user data or system info | |||||||
> > | Special text strings expand on the fly to display dynamic content, such as user data or system info | |||||||
TWikiVariables are text strings - %VARIABLE% or %VARIABLE{ parameter="value" }% - that expand into content whenever a topic is rendered for viewing. There are two types of variables: | ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
TWiki Variables Wizard | |||||||
Changed: | ||||||||
< < | ||||||||
> > |
Select a category and a variable
![]()
Build Your Variable:
<----><----> | |||||||
Using VariablesTo use a variable type its name. For example,
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
Note:
| ||||||||
Changed: | ||||||||
< < | Variable Names | |||||||
> > | Variable Names | |||||||
Changed: | ||||||||
< < | Variable names must start with a letter. The following characters can be letters, numbers and the underscore '_'. You can use both upper-case and lower-case letters and you can mix the characteres. E.g. %MYVAR% , %MyVar% , %My2ndVar% , and %My_Var% are all valid variable names. Variables are case sensitive. %MyVAR% and %MYVAR% are not the same variable. | |||||||
> > | Variable names must start with a letter, optionally followed by letters, numbers and underscore '_' characters. Both upper-case and lower-case characters can be used, %MYVAR% , %MyVar% , %My2ndVar% , and %My_Var% are valid names. Variables are case sensitive, e.g. %MyVAR% and %MYVAR% are not the same. | |||||||
Changed: | ||||||||
< < | By convention all settings, predefined variables and variables used by plugins are always UPPER-CASE. | |||||||
> > | By convention all settings, predefined variables and variables handled by extensions are always UPPER-CASE. | |||||||
Line: 45 to 54 | ||||||||
| ||||||||
Added: | ||||||||
> > |
| |||||||
| ||||||||
Line: 82 to 93 | ||||||||
Parameterized Variables (Macros)It is possible to pass parameters to TWiki variables. This is called a macro in a programming language. To define a parameterized variable, set a variable that contains other variables, such as:* Set EXAMPLE = Example variable using %DEFAULT%, %PARAM1% and %PARAM2% * Set DEMO = Demo using %DEFAULT{ default="(undefined)" }%, %PARAM1{ default="(undefined)" }% and %PARAM2{ default="(undefined)" }%A special %DEFAULT% variable denotes the default (nameless) parameter of the calling variable. Variables optionally may list a default="..." parameter that gets used in case the calling variable does not specify that parameter.
To use a parameterized variable (or call a macro), add parameters within the curly brackets, such as:
* %EXAMPLE{ "foo" PARAM1="bar" PARAM2="baz" }% * %DEMO{ "demo" PARAM2="parameter 2" }% -- note that PARAM1 is missingwhich resolves to:
ExampleDefine variables:* Set DRINK = red wine * Set FAVORITE = My %DEFAULT{default="favorite"}% dish is %DISH{default="steak"}%, my %DEFAULT{default="favorite"}% drink is %DRINK%. ![]() %DISH{default="steak"}% ), or as a preferences setting (Set DRINK = ... ).
Use Variables:
%FAVORITE{ DISH="Sushi" DRINK="Sake" }%Returns: My favorite dish is Sushi, my favorite drink is Sake. %FAVORITE{}%Returns: My favorite dish is steak, my favorite drink is red wine. %FAVORITE{ "preferred" }%Returns: My preferred dish is steak, my preferred drink is red wine. View topic | History: r91 < r90 < r89 < r88 | More topic actions... ![]() ![]() Ideas, requests, problems regarding TWiki? Send feedback Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.TWikiVariables. |