Extension:Variables

Variables is a simple MediaWiki extension that allows you to define a variable on a page, use it later in that same page or included templates, change its value, possibly to a value given by an expression in terms of the old value, etc.

It's much like a template, only very lightweight and scoped to only a single page, so you can use many variables on a page without polluting the wiki with huge numbers of templates. Combined with the ParserFunctions extension for best results.

#vardefine


assigns the value specifiedvalue to the (already existing or hereby introduced) variable variablename.

#vardefineecho


works exactly as #vardefine, but the affected value is printed.

Retrieving the value of a variable (#var)
The value of the variable variablename is produced by

If undefined, this produces the empty string; it does not give an error message.

It's possible to define a value for the case that the variable is undefined or void:

This is equivalent to:

but it's much shorter and better arranged.

The value can be used in parser functions, etc.

#varexists

 * returns 1 if the variable is already defined (also when the value is a void string). If the variable is not defined the return value is void.

Examples

 * Note that the ParserFunctions extension must also be installed to use #expr

Compute 2*a + b:

Add one to n:

Compatibility
There are working versions for Variables extension down to MediaWiki 1.8 or even earlier. However, the most recent versions (1.4, 2.x) are only working with MW 1.12+. If you want to use Variables extension with older MW wikis, please see the Pre MW 1.12 subpage for information and download.

Installation
Once you have downloaded the code, place the Variables directory within your MediaWiki extensions directory. Then add the following code near the bottom of your LocalSettings.php file:

Change log
Variables was written by Rob Adams who has released it into the public domain. It was ported to MediaWiki version 1.8 by Hempel. It was ported to MediaWiki 1.10 by Rob Adams. #vardefineecho was added by Xiloynaha, #varexists and #var with an optional default value as well as further bug-fixes by Danwe who also has put it into mediawikis svn repository.

For detailed and most recent history see the RELEASE-NOTES