%META:TOPICINFO{author="TWikiContributor" date="1111929255" format="1.0" version="79"}%
%META:TOPICPARENT{name="WebHome"}%
%TOC%
%STARTINCLUDE%
---# TWiki Variables

_Special text strings expand on the fly to display user data or system info_

<nop>TWikiVariables are text strings - =%<nop>VARIABLE%= - that expand into content whenever a page is rendered for viewing. =VARIABLES= are replaced by data, either user-entered or automatically generated by TWiki (like the date, or the current username). There are predefined variables, and Preference variables that you can configure. You can also define custom variables, with new names and values.

__Notes:__
	* To leave a variable unexpanded, precede it with an exclamation point, e.g. type =!%<nop>TOPIC%= to get !%TOPIC%.
	* Variables are expanded relative to the topic they are _used_ in, not the topic they are _defined_ in.

---++ Predefined Variables

Most predefined variables return values that were either set in the configuration when TWiki was installed, or taken from server info (like current username, or date and time). Many of the variables let you format the appearance of the display results.

	* %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 ==%<nop>INCLUDINGTOPIC%==, ==%<nop>INCLUDE%==, and the mighty ==%<nop>SEARCH%==.

This version of TWiki - %WIKIVERSION% - expands the following variables (enclosed in ==%== percent signs):

%INCLUDE{"TWikiVariablesAtoM"}%
%INCLUDE{"TWikiVariablesNtoZ"}%

__Note:__ Above text is included from TWikiVariablesAtoM and TWikiVariablesNtoZ

#PreferencesVariables
---++ Preferences Variables

Preferences variables are variables defined in the preferences topics:
	1 default in %TWIKIWEB%.%WIKIPREFSTOPIC%
	 1 local site level in %LOCALSITEPREFS%
	1 web-level in %WEBPREFSTOPIC% of each web
	1 user level in individual user topics in %MAINWEB% web
	 1 session variables (if sessions are enabled)
	1 topic level in topics in webs

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.

There are many variables defined by default, and many more you can define, or may have been defined for your site. You can put !%ALL_VARIABLES% into a topic anywhere in your TWiki to get a full listing of the variables defined there. You can also review:
	* %TWIKIWEB%.%WIKIPREFSTOPIC%
	* %LOCALSITEPREFS%
	* the template topic for new users
	* the default _default.%WEBPREFSTOPIC%
	* and TWikiAccessControl for details about security settings

#SettingPrefs
---++ Setting Variables

	* 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] = [value]
<blockquote style="background-color:#f9f9f9">
*Examples:*
	* ==<nop>Set VARIABLENAME = value==
		* ==<nop>Set VARIABLENAME = value==
</blockquote>
Spaces between the = sign and the value will be ignored. You can split a value over several lines by starting following lines with [multiple of 3 spaces] - as long as you don't try to use * as the first character on the following line.
<blockquote style="background-color:#f9f9f9">
*Example:*
<pre>
	* <nop>Set VARIABLENAME = value starts here
	and continues here
</pre>
</blockquote>

You can also set preference 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.

---++ Local values for variables
Certain topics (a user's 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:
<verbatim>
	* Set EDITBOXHEIGHT = 10
	* Local EDITBOXHEIGHT = 20
</verbatim>
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! %<nop>ALL_VARIABLES% 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.

---++ Creating Custom Variables

	* You can add your own Variables for us across an entire site or a single web, using the standard [[#SettingPrefs][Variables syntax]]. Whatever you include in your Variable will be expanded on display, exactly as if it had been entered directly.

<blockquote style="background-color:#f9f9f9">
*Example: Create a custom logo variable* <br />
	* To place a logo anywhere in a web by typing ==%<nop>MYLOGO%==, define the Variable on the web's WebPreferences page, and upload a logo file, ex: =mylogo.gif=. You can upload by [[FileAttachment][attaching the file]] to WebPreferences, or, to avoid clutter, to any other topic in the same web, ex: =LogoTopic=:
		* ==<nop>Set MYLOGO = %<nop>PUBURL%/<nop>TWiki/LogoTopic/mylogo.gif== 
</blockquote>

%STOPINCLUDE%

__Related Topics:__ UserDocumentationCategory

<!-- Do _not_ attempt to edit this topic; it is auto-generated. Please add comments/questions/remarks to the Dev topic instead. -->
