# TWiki Variables _Special text strings expand on the fly to display user data or system info_ TWikiVariables are text strings - `%VARIABLE%` - that expand into content whenever a page is opened. When a topic is rendered for viewing, `VARIABLES` are replaced by data, either user-entered, or info automatically generated by TWiki (like the date, or the current username). There are predefined variables, and Preference variables that you configure. You can also define custom variables, with new names and values. ## Predefined Variables Most predefined variables return values that were either set in the **lib/twiki.cfg** file, 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 **%INCLUDINGTOPIC%**, **%INCLUDE%**, and the mighty **%SEARCH%**. This version of TWiki - TWiki-4.1.2, Sat, 03 Mar 2007, build 13046 - expands the following variables (enclosed in **%** percent signs):
Variable: Expanded to:
%WIKIHOMEURL% The base script URL of %WIKITOOLNAME%, is the link of the Home icon in the upper left corner, is %WIKIHOMEURL%
%SCRIPTURL% The script URL of %WIKITOOLNAME%, is http://www.dementia.org/twiki/
%SCRIPTURLPATH% The path of the script URL of %WIKITOOLNAME%, is http://www.dementia.org/twiki/
%SCRIPTSUFFIX% The script suffix, ex: .pl, .cgi is
%PUBURL% The public URL of TWiki, is http://www.dementia.org/twiki//view
Example: You can refer to a file attached to another topic as %PUBURL%/%WEB%/OtherTopic/image.gif
%PUBURLPATH% The path of the public URL of %WIKITOOLNAME%, is http://www.dementia.org/twiki//view
%ATTACHURL% The attachment URL of the current topic, is http://www.dementia.org/twiki//view
Example: If you attach a file you can refer to it as %ATTACHURL%/image.gif
%ATTACHURLPATH% The path of the attachment URL of the current topic, is http://www.dementia.org/twiki//view
%URLPARAM{"name"}% Returns the value of a URL parameter. Note that there is a low risk that this variable could be misused for cross-scripting. Ex: %URLPARAM{"skin"}% returns print for a .../view/%WEB%/%TOPIC%?skin=print URL. Is
%URLENCODE{"string"}% Encodes a string for use as a URL parameter. Ex: %URLENCODE{"spaced name"}% returns spaced%20name
%WIKITOOLNAME% The name of your TWiki site - %WIKITOOLNAME%
%WIKIVERSION% Your current TWiki version - TWiki-4.1.2, Sat, 03 Mar 2007, build 13046
%USERNAME% Your login username - admin
%WIKINAME% Your Wiki username. Same as %USERNAME% if not defined in the [[Main/TWikiUsers]] topic. Is admin
%WIKIUSERNAME% Your %WIKINAME% including the Main web name - always use full signatures - Main.admin
%MAINWEB% The web containing [[Main/TWikiUsers]], [[Main/OfficeLocations]] and [[Main/TWikiGroups]] is Main
%TWIKIWEB% The web containing all documentation and site-wide preference settings for %WIKITOOLNAME% - TWiki
%WEB% The current web is %WEB%
%BASEWEB% The web name where the includes started, e.g. the web of the first topic of nested includes. Same as %WEB% in case there is no include.
%INCLUDINGWEB% The web name of the topic that includes the current topic - same as %WEB% if there is no INCLUDE.
%HOMETOPIC% The home topic in each web - [[Main/WebHome]]
%NOTIFYTOPIC% The notify topic in each web - [[Main/WebNotify]]
%WIKIUSERSTOPIC% The index topic of all registered users - TWikiUsers
%WIKIPREFSTOPIC% The site-wide preferences topic - TWikiPreferences
%WEBPREFSTOPIC% The local web preferences topic in each web - WebPreferences
%STATISTICSTOPIC% The web statistics topic WebStatistics
%TOPIC% The current topic name - %TOPIC%
%BASETOPIC% The name of the topic where a single or nested INCLUDE started - same as %TOPIC% if there is no INCLUDE.
%INCLUDINGTOPIC% The name of the topic that includes the current topic. Same as %TOPIC% in case there is no include.
%SPACEDTOPIC% The current topic name with added spaces, for regular expression search of Ref-By, is
%TOPICLIST{"format"}% Topic index of a web. The "format" defines the format of one topic item. It may include variables: The $name variable gets expanded to the topic name; the $web variable gets expanded to the name of the web. Parameters are format, separator and web:
Parameter: Description: Default:
"format" Format of one line, may include $name and $web variables "$name"
format="format" (Alternative to above) "$name"
separator=", " line separator "\n" (new line)
web="Name" Name of web Current web
Examples:
%TOPICLIST{"   * $web.$name"}% creates a bullet list of all topics.
%TOPICLIST{separator=", "}% creates a comma separated list of all topics.
%TOPICLIST{" <option>$name</option>"}% creates an option list (for drop down menus).
%WEBLIST{"format"}% Web index, ex: list of all webs. Hidden webs are excluded, e.g. webs with a NOSEARCHALL=on preference variable. The "format" defines the format of one web item. The $name variable gets expanded to the name of the web, $qname gets expanded to double quoted name, $marker to marker where web matches selection. Parameters are format, separator and web:
Parameter: Description: Default:
"format" Format of one line, may include $name variable "$name"
format="format" (Alternative to above) "$name"
separator=", " line separator "\n" (new line)
webs="public" comma sep list of Web, public expands to all non-hidden "public"
marker="selected" Text for $marker where item matches selection, otherwise equals "" "selected"
selection="%WEB%" Current value to be selected in list section="%WEB%"
Examples:
%WEBLIST{"   * [[$name.WebHome]]"}% creates a bullet list of all webs.
%WEBLIST{"<option $marker value=$qname>$name</option>" webs="Trash,public" selection="%WEB%" separator=" "}% Dropdown of all public Webs + Trash Web, current Web highlighted.
%GMTIME% GM time, is 29 Jun 2010 - 15:40
%GMTIME{"format"}% Formatted GM time based on time variables.
Variable: Unit: Example
$seconds seconds 59
$minutes minutes 59
$hours hours 23
$day day of month 31
$month month in ISO format Dec
$mo 2 digit month 12
$year 4 digit year 1999
$ye 2 digit year 99
Variables can be shortened to 3 characters. Example:
%GMTIME{"$day $month, $year - $hour:$min:$sec"}% is
29 Jun, 2010 - 15:40:25
%SERVERTIME% Server time, is 29 Jun 2010 - 11:40
%SERVERTIME{"format"}% Formatted server time.
Example: %SERVERTIME{"$hou:$min"}% is 11:40
%HTTP_HOST% HTTP_HOST environment variable, is
%REMOTE_ADDR% REMOTE_ADDR environment variable, is
%REMOTE_PORT% REMOTE_PORT environment variable, is
%REMOTE_USER% REMOTE_USER environment variable, is
%INCLUDE{"page" ...}% Server side include to [[Main/IncludeTopicsAndWebPages]]:
Parameter: Description: Default:
"SomeTopic" The name of a topic located in the current web, i.e. %INCLUDE{"WebNotify"}%  
"Web.Topic" A topic in another web, i.e. %INCLUDE{"TWiki.SiteMap"}%  
"http://..." A full qualified URL, i.e. %INCLUDE{"http://twiki.org/"}%  
pattern="..." A [[Main/RegularExpression]] pattern to include a subset of a topic or page none
rev="1.2" Include a previous topic revision; N/A for URLs top revision
%STARTINCLUDE% If present in included topic, start to include text from this location up to the end, or up to the location of the %STOPINCLUDE% variable. A normal view of the topic shows everyting exept the %STARTINCLUDE% variable itself.
%STOPINCLUDE% If present in included topic, stop to include text at this location and ignore the remaining text. A normal view of the topic shows everyting exept the %STOPINCLUDE% variable itself.
%TOC% Table of Contents of current topic.
%TOC{"SomeTopic" ...}% Table of Contents. Shows a TOC that is generated automatically based on headings of a topic. Headings in [[Main/WikiSyntax]] ("---++ text") and HTML ("<h2>text</h2>") are taken into account. Any heading text after "!!" is excluded from the TOC; for example, write "---+!! text" if you do not want to list a header in the TOC. Parameters are topic name, web and depth:
Parameter: Description: Default:
"TopicName" topic name Current topic
web="Name" Name of web Current web
depth="2" Limit depth of headings shown in TOC 6
Examples: %TOC{depth="2"}%, %TOC{"TWikiDocumentation" web="TWiki"}%
%SEARCH{"text" ...}% Inline search, shows a search result embedded in a topic. Parameters are the search term, web, scope, order and many more: [1]
Parameter: Description: Default:
"text" Search term. Is a regular expression or literal, depending on the regex parameter. For regular expressions ";" is used to mean and e.g. "search;agrep" will find all topic containing search and agrep. required
search="text" (Alternative to above) N/A
web="Name"
web="Main Know"
web="all"
Wiki web to search: A web, a list of webs separated by whitespace, or all webs. [2] Current web
scope="topic"
scope="text"
Search topic name (title) or in the text (body) of the topic Topic text (body)
order="topic"
order="modified"
order="editby"
order=
 "formfield(name)"
Sort the results of search by the topic names, last modified time, last editor, or named field of [[Main/TWikiForms]] Sort by topic name
limit="all"
limit="16"
Limit the number of results returned All results
regex="on" [[Main/RegularExpression]] search; also enables ";" as and Literal search
reverse="on" Reverse the direction of the search Ascending search
casesensitive="on" Case sensitive search Ignore case
nosummary="on" Show topic title only Show topic summary
bookview="on" [[Main/BookView]] search, e.g. show complete topic text Show topic summary
nosearch="on" Suppress search string Show search string
noheader="on" Suppress search header
Topics: Changed: By:
Show search header
nototal="on" Do not show number of topics found Show number
header="..."
format="..."
Custom format results: see [[Main/FormattedSearch]] for usage, variables & examples Results in table
Regular example: %SEARCH{"wiki" web="Main" scope="topic"}%
Formatted example: %SEARCH{"FAQ" scope="topic" nosearch="on" nototal="on" header="| *Topic: * | *Summary: * |" format="| $topic | $summary |"% (displays results in a table with header - [[Main/FormattedSearch]])
%H% If the TWiki:Plugins.TablePlugin is installed, you may set a %TABLE{}% variable just before the %SEARCH{}% to alter the output of a search. Example: %TABLE{ tablewidth="90%" }%
%METASEARCH{...}% Special search of meta data
Parameter: Description: Default:
type="topicmoved" What sort of search is required?
"topicmoved" if search for a topic that may have been moved
"parent" if searching for topics that have a specific parent i.e. its children
required
web="%WEB%" Wiki web to search: A web, a list of webs separated by whitespace, or all webs. required
topic="%TOPIC%" The topic the search relates to required
title="Title" Text that is prepended to any search results required
Example: %METASEARCH{type="topicmoved" web="%WEB%" topic="%TOPIC%" title="This topic used to exist and was moved to: "}%, you may want to use this in [[Main/WebTopicViewTemplate]] and [[Main/WebTopicNonWikiTemplate]]
%METASEARCH{type="parent" web="%WEB%" topic="%TOPIC%" title="Children: "}%
%VAR{"NAME" web="Web"}% Get a preference value from a web other then the current one. Example: To get %WEBBGCOLOR% of the Main web write %VAR{"WEBBGCOLOR" web="Main"}%, is
> [1] > > **_Note_** > > : The search form uses identical names for input fields. > > [2] **_Note_**: A web can be excluded from a **web="all"** search if you define a **NOSEARCHALL=on** variable in its [[WebPreferences]]. ## Preferences Variables Additional variables are defined in the preferences ( site-level ( **_SL_** ) in [[TWikiPreferences]], web-level ( **_WL_** ) in [[WebPreferences]] of each web, and user level ( **_UL_** ) preferences in individual user topics):
Variable: Level: What:
%WIKIWEBMASTER% SL Webmaster email address (sender of email notifications) , is
%WIKIWEBLIST% SL List of %WIKITOOLNAME% webs (in upper right corner of topics)
%WEBTOPICLIST% WL Common links of web (second line of topics)
%WEBCOPYRIGHT% SL , WL Copyright notice (bottom right corner of topics)
%WEBBGCOLOR% WL Background color of web
%NOSEARCHALL% WL Exclude web from a web="all" search (set variable to on for hidden webs)
%NEWTOPICBGCOLOR% SL , UL Background color of non existing topic. ( UL needs authentication for topic views )
%NEWTOPICFONTCOLOR% SL , UL Font color of non existing topic. ( UL needs authentication for topic views )
%EDITBOXWIDTH% SL , UL Horizontal size of edit box, is %EDITBOXWIDTH%
%EDITBOXHEIGHT% SL , UL Vertical size of edit box, is %EDITBOXHEIGHT%
%EDITBOXSTYLE% SL , UL Style of text edit box. Set to width: 99% for full window width (default; overwrites the EDITBOXWIDTH setting), or width: auto to disable. Value is: %EDITBOXSTYLE%
%RELEASEEDITLOCKCHECKBOX% SL , UL Default state of the "Release edit lock" ([[Main/UnlockTopic]]) check box in preview. Checkbox is initially checked if Set RELEASEEDITLOCKCHECKBOX = checked="checked", or unchecked if empty. If checked, make sure to click on Edit to do more changes; do not go back in your browser to the edit page, or you risk that someone else will edit the topic at the same time! Value is: %RELEASEEDITLOCKCHECKBOX%
%DONTNOTIFYCHECKBOX% SL , UL Default state of the "Minor Changes, Don't Notify" ([[Main/DontNotify]]) check box in preview. Check box is initially checked if Set DONTNOTIFYCHECKBOX = checked="checked", or unchecked if empty. Value is: %DONTNOTIFYCHECKBOX%
%ATTACHLINKBOX% SL , UL Default state of the link check box in the attach file page. Check box is initially checked if value is set to CHECKED , unchecked if empty. If checked, a link is created to the attached file at the end of the topic. Value is: %ATTACHLINKBOX%
%HTTP_EQUIV_ON_VIEW% SL http-equiv meta tags for view, rdiff, attach, search* scripts.
%HTTP_EQUIV_ON_EDIT% SL , UL http-equiv meta tags for edit script.
%HTTP_EQUIV_ON_PREVIEW% SL , UL http-equiv meta tags for preview script.
%DENYWEBCHANGE% WL List of users and groups who are not allowed to change topics in the %WIKITOOLNAME% web. (More in [[Main/TWikiAccessControl]])
%ALLOWWEBCHANGE% WL List of users and groups who are allowed to change topics in the %WIKITOOLNAME% web. (More in [[Main/TWikiAccessControl]])
%DENYTOPICCHANGE% (any topic) List of users and groups who are not allowed to change the current topic. (More in [[Main/TWikiAccessControl]])
%ALLOWTOPICCHANGE% (any topic) List of users and groups who are allowed to change the current topic. (More in [[Main/TWikiAccessControl]])
%DENYWEBRENAME% WL List of users and groups who are not allowed to rename topics in the %WIKITOOLNAME% web. (More in [[Main/TWikiAccessControl]])
%ALLOWWEBRENAME% WL List of users and groups who are allowed to rename topics in the %WIKITOOLNAME% web. (More in [[Main/TWikiAccessControl]])
%DENYTOPICRENAME% (any topic) List of users and groups who are not allowed to rename the current topic. (More in [[Main/TWikiAccessControl]])
%ALLOWTOPICRENAME% (any topic) List of users and groups who are allowed to rename the current topic. (More in [[Main/TWikiAccessControl]])

%FINALPREFERENCES% SL , WL List of preferences that are not allowed to be overridden by next level preferences
> **_Note:_** > > There are some more useful variables defined in the > > [[TWikiPreferences]] > > like > > `%BR%` > > for line break, colors like > > `%RED%` > > for colored text and small icons like > > `%H%` > > for a %H% Help icon. ## Setting Preferences - The syntax for Preferences 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] = [value]
**_Examples:_** - **Set VARIABLENAME = value** - **Set VARIABLENAME = value** ## Creating Custom Variables - You can add your own Preference Variables for us across an entire site or a single web, using the standard [[Preferences syntax|Main/WebHome#SettingPrefs]]. Whatever you include in your Variable will be expanded on display, exactly as if it had been entered directly. You can place formatted text, page links, image paths. > **Example: Create a custom logo variable the %WEB% web** > >
> > - To place a logo anywhere in a web by typing **%MYLOGO%**, define the Variable on the web's [[WebPreferences]] page, 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, ex: `LogoTopic`: > - **Set MYLOGO = %PUBURL%/TWiki/LogoTopic/mylogo.gif** -- [[PeterThoeny]] - 19 Jan 2003
-- [[MikeMannix]] - 12 May 2002