attachment upload
[openafs-wiki.git] / TWiki / TWikiVariables.mdwn
1 # <a name="TWiki Variables"></a> TWiki Variables
2
3 _Special text strings expand on the fly to display user data or system info_
4
5 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:
6
7 1. Preferences variables: Can be defined and changed by the user
8 2. Predefined variables: Defined by the TWiki system or by Plugins (for example, the [[SpreadSheetPlugin]] introduces a `%CALC{}%` variable)
9
10 <div>
11   <ul>
12     <li><a href="#TWiki Variables"> TWiki Variables</a><ul>
13         <li><a href="#Using Variables"> Using Variables</a></li>
14         <li><a href="#Variable Names"> Variable Names</a></li>
15         <li><a href="#Preferences Variables"> Preferences Variables</a><ul>
16             <li><a href="#Setting Preferences Variables"> Setting Preferences Variables</a></li>
17             <li><a href="#Access Control Variables"> Access Control Variables</a></li>
18             <li><a href="#Local values for variables"> Local values for variables</a></li>
19             <li><a href="#Frequently Used Preferences Vari"> Frequently Used Preferences Variables</a></li>
20           </ul>
21         </li>
22         <li><a href="#Predefined Variables"> Predefined Variables</a></li>
23       </ul>
24     </li>
25     <li><a href="#TWiki Installation Error">TWiki Installation Error</a></li>
26   </ul>
27 </div>
28
29 ## <a name="Using Variables"></a> Using Variables
30
31 To use a variable type its name. For example,
32
33 - type `%T%` to get %T% (a preferences variable)
34 - type `%TOPIC%` to get `%TOPIC%` (a predefined variable)
35 - type `%CALC{ "$UPPER(Text)" }%` to get `TEXT` (a variable defined by Plugin)
36
37 **_Note:_**
38
39 - To leave a variable unexpanded, precede it with an exclamation point, e.g. type `!%TOPIC%` to get `%TOPIC%`
40 - Variables are expanded relative to the topic they are _used_ in, not the topic they are _defined_ in
41 - Type `%ALLVARIABLES%` to get a full listing of all variables defined for a particular topic
42
43 ## <a name="Variable Names"></a> Variable Names
44
45 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.
46
47 By convention all settings, predefined variables and variables used by plugins are always UPPER-CASE.
48
49 <a name="SettingPrefs"></a> <a name="PreferencesVariables"></a>
50
51 ## <a name="Preferences Variables"></a> Preferences Variables
52
53 Unlike predefined variables, preferences variables can be defined by the user in various places.
54
55 ### <a name="Setting Preferences Variables"></a> Setting Preferences Variables
56
57 You can set variables in all the following places:
58
59 1. local site level in [[%SYSTEMWEB%.TWikiPreferences|SYSTEMWEB/TWikiPreferences]]
60 2. plugin topics (see [[TWikiPlugins]])
61 3. local site level in [[Main.TWikiPreferences|Main/TWikiPreferences]]
62 4. user level in individual user topics in %USERSWEB% web
63 5. web level in [[WebPreferences]] of each web
64 6. topic level in topics in webs
65 7. session variables (if sessions are enabled)
66
67 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.
68
69 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, <code>**Preview**</code> will show the wrong thing, and you must <code>**Save**</code> the topic to see it correctly.
70
71 The syntax for setting Variables is the same anywhere in TWiki (on its own TWiki bullet line, including nested bullets): <br />`[multiple of 3 spaces] * [space] Set [space] VARIABLENAME [space] = [space] value`
72
73 > **Examples:**
74 >
75 > - <code>**Set VARIABLENAME = value**</code>
76 >   - <code>**Set VARIABLENAME = value**</code>
77
78 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.
79
80 > **Example:**
81 >
82 >        * Set VARIABLENAME = value starts here
83 >          and continues here
84
85 Whatever you include in your Variable will be expanded on display, exactly as if it had been entered directly.
86
87 > **Example: Create a custom logo variable**
88 >
89 > <br />
90 >
91 > - To place a logo anywhere in a web by typing <code>**%MYLOGO%**</code>, define the Variable on the web's [[WebPreferences]] topic, and upload a logo file, ex: `mylogo.gif`. You can upload by [[attaching the file|Main/FileAttachment]] to [[WebPreferences]], or, to avoid clutter, to any other topic in the same web, e.g. `LogoTopic`. Sample variable setting in [[WebPreferences]]:
92 >   - <code>**Set MYLOGO = %PUBURL%/%WEB%/LogoTopic/mylogo.gif**</code>
93
94 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.
95
96 ### <a name="Access Control Variables"></a> Access Control Variables
97
98 These are special types of preferences variables to control access to content. [[TWikiAccessControl]] explains these security settings in detail.
99
100 ### <a name="Local values for variables"></a> Local values for variables
101
102 Certain topics (a users home topic, web site and default preferences topics) have a problem; variables defined in those topics can have two meanings. For example, consider a user topic. A user may want to use a double-height edit box when they are editing their home topic - but **only** when editing their home topic. The rest of the time, they want to have a normal edit box. This separation is achieved using `Local` in place of `Set` in the variable definition. For example, if the user sets the following in their home topic:
103
104        * Set EDITBOXHEIGHT = 10
105        * Local EDITBOXHEIGHT = 20
106
107 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.
108
109 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.
110
111 ### <a name="Frequently Used Preferences Vari"></a> Frequently Used Preferences Variables
112
113 The following preferences variables are frequently used. They are defined in [[TWikiPreferences#Miscellaneous_Settings]]:
114
115 - `%BR%` - line break
116 - `%BULLET%` - bullet sign
117 - `%BB%` - line break and bullet combined
118 - `%BB2%` - indented line break and bullet
119 - `%RED% text %ENDCOLOR%` - colored text (also `%YELLOW%`, `%ORANGE%`, `%PINK%`, `%PURPLE%`, `%TEAL%`, `%NAVY%`, `%BLUE%`, `%AQUA%`, `%LIME%`, `%GREEN%`, `%OLIVE%`, `%MAROON%`, `%BROWN%`, `%BLACK%`, `%GRAY%`, `%SILVER%`, `%WHITE%`)
120 - `%H%` - %H% Help icon
121 - `%I%` - %I% Idea icon
122 - `%M%` - %M% Moved to icon
123 - `%N%` - %N% New icon
124 - `%P%` - %P% Refactor icon
125 - `%Q%` - %Q% Question icon
126 - `%S%` - %S% Pick icon
127 - `%T%` - %T% Tip icon
128 - `%U%` - %U% Updated icon
129 - `%X%` - %X% Alert icon
130 - `%Y%` - %Y% Done icon
131
132 There are additional useful preferences variables defined in [[TWikiPreferences]], in [[Main.TWikiPreferences|Main/TWikiPreferences]], and in [[WebPreferences]] of every web.
133
134 <a name="PreDef"></a>
135
136 ## <a name="Predefined Variables"></a> Predefined Variables
137
138 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.
139
140 - %X% Predefined variables can be overridden by [[preferences variables|Main/WebHome#PreferencesVariables]] (except TOPIC and WEB)
141 - %X% Plugins may extend the set of predefined variables (see individual Plugins topics for details)
142 - %T% **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%`.
143
144 This version of TWiki - TWiki-4.1.2, Sat, 03 Mar 2007, build 13046 - predefines the following variables:
145
146 # <a name="TWiki Installation Error"></a> TWiki Installation Error
147
148 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
149
150 **_Related Topics:_** [[UserDocumentationCategory]]