Difference: TWikiVariables (85 vs. 86)

Revision 862010-05-25 - TWikiContributor

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

TWiki Variables

Line: 6 to 6
 Special text strings expand on the fly to display 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:

Added:
>
>
 
  1. Preferences variables: Can be defined and changed by the user
Changed:
<
<
  1. Predefined variables: Defined by the TWiki system or by Plugins (for example, the SpreadSheetPlugin introduces a %CALC{}% variable)
>
>
  1. Predefined variables: Defined by the TWiki system or by plugins (for example, the SpreadSheetPlugin introduces a %CALC{}% variable)
 
Line: 16 to 17
 To use a variable type its name. For example,
  • type %T% to get TIP (a preferences variable)
  • type %TOPIC% to get TWikiVariables (a predefined variable)
Changed:
<
<
  • type %CALC{ "$UPPER(Text)" }% to get TEXT (a variable defined by Plugin)
>
>
  • type %CALC{ "$UPPER(Text)" }% to get TEXT (a variable defined by a plugin)
  Note:
  • To leave a variable unexpanded, precede it with an exclamation point, e.g. type !%TOPIC% to get %TOPIC%
Line: 36 to 37
 

Setting Preferences Variables

You can set variables in all the following places:
Changed:
<
<
  1. local site level in TWiki.TWikiPreferences
>
>
  1. system level in TWiki.TWikiPreferences
 
  1. plugin topics (see TWikiPlugins)
  2. local site level in Main.TWikiPreferences
  3. user level in individual user topics in Main web
Line: 46 to 47
  Settings at higher-numbered levels override settings of the same variable at lower numbered levels, unless the variable was included in the setting of FINALPREFERENCES at a lower-numbered level, in which case it is locked at the value it has at that level.
Changed:
<
<
If you are setting a variable and using it in the same topic, note that TWiki reads all the variable settings from the saved version of the topic before it displays anything. This means you can use a variable anywhere in the topic, even if you set it somewhere inconspicuous near the end. But beware: it also means that if you change the setting of a variable you are using in the same topic, Preview will show the wrong thing, and you must Save the topic to see it correctly.
>
>
If you are setting a variable and using it in the same topic, note that TWiki reads all the variable settings from the saved version of the topic before it displays anything. This means you can use a variable anywhere in the topic, even if you set it somewhere inconspicuous near the end. But beware: it also means that if you change the setting of a variable you are using in the same topic, preview will show the wrong thing, and you must save the topic to see it correctly.

The syntax for setting variables is the same anywhere in TWiki (on its own TWiki bullet line, including nested bullets):
[multiple of 3 spaces] * [space] Set [space] VARIABLENAME [space] = [space] value

 
Deleted:
<
<
The syntax for setting Variables is the same anywhere in TWiki (on its own TWiki bullet line, including nested bullets):
[multiple of 3 spaces] * [space] Set [space] VARIABLENAME [space] = [space] value
 Examples:
Changed:
<
<
  • Set VARIABLENAME = value
    • Set VARIABLENAME = value
>
>
   * Set VARIABLENAME1 = value
      * Set VARIABLENAME2 = value
 Spaces between the = sign and the value will be ignored. You can split a value over several lines by indenting following lines with spaces - as long as you don't try to use * as the first character on the following line.
Changed:
<
<
>
>
 Example:
   * Set VARIABLENAME = value starts here
     and continues here
Deleted:
<
<
 
Changed:
<
<
Whatever you include in your Variable will be expanded on display, exactly as if it had been entered directly.
>
>
Whatever you include in your variable will be expanded on display, exactly as if it had been entered directly.
 
Deleted:
<
<
 Example: Create a custom logo variable
  • To place a logo anywhere in a web by typing %MYLOGO%, define the Variable on the web's WebPreferences topic, and upload a logo file, ex: mylogo.gif. You can upload by attaching the file to WebPreferences, or, to avoid clutter, to any other topic in the same web, e.g. LogoTopic. Sample variable setting in WebPreferences:
Changed:
<
<
    • Set MYLOGO = %PUBURL%/%WEB%/LogoTopic/mylogo.gif
>
>
      * Set MYLOGO = %PUBURL%/%WEB%/LogoTopic/mylogo.gif
 
Changed:
<
<
You can also set preferences variables on a topic by clicking the link Edit topic preference settings under More topic actions. Preferences set in this manner are not visible in the topic text, but take effect nevertheless.
>
>
You can also set preferences variables on a topic by clicking the link Edit topic preference settings under More topic actions. Use the same * Set VARIABLENAME = value syntax. Preferences set in this manner are not visible in the topic text, but take effect nevertheless.
 

Access Control Variables

Line: 83 to 86
 
  • Set EDITBOXHEIGHT = 10
  • Local EDITBOXHEIGHT = 20
Changed:
<
<
Then when they are editing any other topic, they will get a 10 high edit box. However when they are editing their home topic, they will get a 20 high edit box. Local can be used wherever a preference needs to take a different value depending on where the current operation is being performed.
>
>
Then when they are editing any other topic, they will get a 10 high edit box. However when they are editing their home topic, they will get a 20 high edit box. Local can be used wherever a preference needs to take a different value depending on where the current operation is being performed.
  Use this powerful feature with great care! %ALLVARIABLES% can be used to get a listing of the values of all variables in their evaluation order, so you can see variable scope if you get confused.

Frequently Used Preferences Variables

The following preferences variables are frequently used. They are defined in TWikiPreferences#Miscellaneous_Settings:

Added:
>
>
  • %BB% - line break and bullet combined
  • %BB2% - level 2 bullet with line break
  • %BB3% - level 3 bullet with line break
  • %BB4% - level 4 bullet with line break
 
  • %BR% - line break
  • %BULLET% - bullet sign
Changed:
<
<
  • %BB% - line break and bullet combined
  • %BB2% - indented line break and bullet
  • %RED% text %ENDCOLOR% - colored text (also %YELLOW%, %ORANGE%, %PINK%, %PURPLE%, %TEAL%, %NAVY%, %BLUE%, %AQUA%, %LIME%, %GREEN%, %OLIVE%, %MAROON%, %BROWN%, %BLACK%, %GRAY%, %SILVER%, %WHITE%)
>
>
  • %CARET% - caret symbol
  • %VBAR% - vertical bar
 
  • %H% - HELP Help icon
  • %I% - IDEA! Idea icon
  • %M% - MOVED TO... Moved to icon
Line: 107 to 112
 
  • %U% - UPDATED Updated icon
  • %X% - ALERT! Alert icon
  • %Y% - DONE Done icon
Added:
>
>
  • %RED% text %ENDCOLOR% - colored text (also %YELLOW%, %ORANGE%, %PINK%, %PURPLE%, %TEAL%, %NAVY%, %BLUE%, %AQUA%, %LIME%, %GREEN%, %OLIVE%, %MAROON%, %BROWN%, %BLACK%, %GRAY%, %SILVER%, %WHITE%)
  • %REDBG% text %ENDBG% - colored background (also %YELLOWBG%, %ORANGEBG%, %PINKBG%, %PURPLEBG%, %TEALBG%, %NAVYBG%, %BLUEBG%, %AQUABG%, %LIMEBG%, %GREENBG%, %OLIVEBG%, %MAROONBG%, %BROWNBG%, %BLACKBG%, %GRAYBG%, %SILVERBG%, %WHITEBG%)
  There are additional useful preferences variables defined in TWikiPreferences, in Main.TWikiPreferences, and in WebPreferences of every web.
Line: 117 to 124
 Most predefined variables return values that were either set in the configuration when TWiki was installed, or taken from server info (such as current username, or date and time). Some, like %SEARCH%, are powerful and general tools.

Changed:
<
<
  • ALERT! Plugins may extend the set of predefined variables (see individual Plugins topics for details)
>
>
  • ALERT! Plugins may extend the set of predefined variables (see individual plugin topics for details)
 
  • TIP Take the time to thoroughly read through ALL preference variables. If you actively configure your site, review variables periodically. They cover a wide range of functions, and it can be easy to miss the one perfect variable for something you have in mind. For example, see %INCLUDINGTOPIC%, %INCLUDE%, and the mighty %SEARCH%.

Search predefined variables

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 1999-2019 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.TWikiVariables.