3k Associates Inc HP3000 FAQ TWiki TWiki > TWiki > TWikiVariables TWiki webs:
Main | TWiki | Sandbox
TWiki . { Welcome | Register | Changes | Topics | Index | Search | Go }

TWiki Variables

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:

  1. Preferences variables: Can be defined and changed by the user
  2. Predefined variables: Defined by the TWiki system or by Plugins (for example, the SpreadSheetPlugin introduces a %CALC{}% variable)

Using Variables

To use a variable type its name. For example,

Note:

Preferences Variables

Unlike predefined variables, preferences variables can be defined by the user in various places.

Setting Preferences Variables

You can set variables in all the following places:
  1. local site level in TWikiPreferences
  2. user level in individual user topics in Main web
  3. web level in WebPreferences of each web
  4. topic level in topics in webs
  5. plugin topics (see TWikiPlugins)
  6. session variables (if sessions are enabled)

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.

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:
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.
Example:
   * Set VARIABLENAME = value starts here
     and continues here

Whatever you include in your Variable will be expanded on display, exactly as if it had been entered directly.

Example: Create a custom logo variable

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.

Access Control Variables

These are special types of preferences variables to control access to content. TWikiAccessControl explains these security settings in detail.

Local values for variables

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:
   * Set EDITBOXHEIGHT = 10
   * Local EDITBOXHEIGHT = 20
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:

There are additional useful preferences variables defined in TWikiPreferences, in Main.TWikiPreferences, and in WebPreferences of every web.

Predefined Variables

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.

This version of TWiki - Wed, 08 Feb 2006 build 8740 - predefines the following variables:

ACTIVATEDPLUGINS -- list of currently activated plugins

ALLVARIABLES -- list of currently defined TWikiVariables

ATTACHURL -- full URL for attachments in the current topic

ATTACHURLPATH -- path of the attachment URL of the current topic

AUTHREALM -- authentication realm

BASETOPIC -- base topic where an INCLUDE started

BASEWEB -- base web where an INCLUDE started

DATE -- signature format date

DISPLAYTIME -- display time

DISPLAYTIME{"format"} -- formatted display time

ENCODE{"string"} -- encodes a string to HTML entities

ENDSECTION{"name"} -- marks the end of a named section within a topic

FAILEDPLUGINS -- debugging for plugins that failed to load, and handler list

FORMFIELD{"fieldname"} -- renders a field in the form attached to some topic

GMTIME -- GM time

GMTIME{"format"} -- formatted GM time

HOMETOPIC -- home topic in each web

HTTP -- get HTTP headers

HTTPS -- get HTTPS headers

HTTP_HOST -- environment variable

ICON{"name"} -- small documentation graphic or icon of common attachment types

ICONURL{"name"} -- URL of small documentation graphic or icon

ICONURLPATH{"name"} -- URL path of small documentation graphic or icon

IF{"condition" ...} -- simple conditionals

INCLUDE{"page"} -- include other topic or web page

INCLUDINGTOPIC -- name of topic that includes current topic

INCLUDINGWEB -- web that includes current topic

LANGUAGE -- current user's language

LANGUAGES -- list available TWiki languages

LOCALSITEPREFS -- web.topicname of site preferences topic

LOGIN -- present a full login link

LOGOUT -- present a full logout link

MAKETEXT -- creates text using TWiki's I18N infrastructure

MAINWEB -- name of Main web

META -- displays meta-data

METASEARCH -- special search of meta data

NOP -- template text not to be expanded in instantiated topics

NOTIFYTOPIC -- name of the notify topic

PLUGINDESCRIPTIONS -- list of plugin descriptions

PLUGINVERSION -- the version of a TWiki Plugin, or the TWiki Plugins API

PUBURL -- the base URL of attachments

PUBURLPATH -- the base URL path of attachments

QUERYSTRING -- full, unprocessed string of parameters to this URL

REMOTE_ADDR -- environment variable

REMOTE_PORT -- environment variable

REMOTE_USER -- environment variable

REVINFO -- revision information of current topic

REVINFO{"format"} -- formatted revision information of topic

SCRIPTNAME -- name of current script

SCRIPTSUFFIX -- script suffix

SCRIPTURL -- base URL of TWiki scripts

SCRIPTURL{"script"} -- URL of TWiki script

SCRIPTURLPATH -- base URL path of TWiki scripts

SCRIPTURLPATH{"script"} -- URL path of TWiki script

SEARCH{"text"} -- search content

SERVERTIME -- server time

SERVERTIME{"format"} -- formatted server time

SESSION_VARIABLE -- get, set or clear a session variable

SESSIONID -- unique ID for this session

SESSIONVAR -- name of CGI and session variable that stores the session ID

SPACEDTOPIC -- topic name, spaced and URL-encoded deprecated

SPACEOUT{"string"} -- renders string with spaces inserted in sensible places

STARTINCLUDE -- start position of topic text if included

STARTSECTION -- marks the start of a section within a topic

STATISTICSTOPIC -- name of statistics topic

STOPINCLUDE -- end position of topic text if included

TOC -- table of contents of current topic

TOC{"Topic"} -- table of contents

TOPIC -- name of current topic