Extension:Variables/zh

变量（Variables）扩展允许您在一个页面定义变量，然后在同样的页面或包括的模板变化它的值，可能是通过表达式在旧值中赋予的值等.

它很像模板，只是占用内存非常少并且作用只能在1个页面，所以你可以在1个页面使用很多个变量而不需要用大数量的模板在这个wiki缓慢下来. 结合解析器函数组件以达到最好的结果.

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


 * 示例： 使iconwidth=25

Works exactly as, but the affected value is printed.


 * 例如： making iconwidth = 

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.


 * 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.

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.

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

计算 ： 加入一个至“n”：

Note

 * This extension is not likely to be enabled for WMF wikis, see T65324, T113859, and T151192.

参见

 * Extension:DynamicFunctions##arg:
 * Extension:MyVariables - Creates new variables in the MediaWiki sense
 * Extension:Loops - Provides parser functions for performing loops
 * Extension:Arrays - Create an array and provide array functions (such as search, split, and sort) and set operations (such as intersect, union and diff)
 * Extension:HashTables - New parser functions for handling hash tables in MediaWiki
 * Extension:HashTables - New parser functions for handling hash tables in MediaWiki