Extension:Variables/pt-br

A extensão Variables ​​permite definir uma variável em uma página, usá-la mais tarde na mesma página ou predefinições incluídas, alterar o seu valor, possivelmente para um valor determinado por uma expressão em termos do valor antigo, etc

É muito parecido com uma predefinição, apenas é muito leve e com escopo para apenas uma única página, assim você pode usar muitas variáveis ​​em uma página, sem abrandar o wiki com um grande número de predefinições. Combine esta extensão com a extensão ParserFunctions para melhores resultados.

#vardefine
Assigns the value specifiedvalue to the (already existing or hereby introduced) variable variablename.


 * Example:  making iconwidth = 25

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


 * Example: making iconwidth = 

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

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

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



This is equivalent to:

but it is much shorter and better arranged. Before version 2.0 though, the default value always was expanded. From version 2.0 on the default only gets expanded in case it is actually used.

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.

#var_final
Experimental new function introduced in Variables 2.0. This function will output the final, last value a variable has at the end of the page rendering. Naturally, the value will be inserted after the parser went over the entire wiki markup, so this function can't be used in other functions, expecting the right value is being used. Example:

The default value will be used if the variable doesn't exist at the final page rendering stage or if its value is an empty string. The default will be expanded right where the function is used, so the parameter will be expanded, even if it won't be needed.

Examples
The ParserFunctions extension must also be installed to use #expr.

Compute : Add one to n:

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, #var_final and #var with optional default value as well as the 2.0 rewrite were contributed by Daniel Werner who is currently maintaining the extension.

For detailed and most recent history see the.