Dplvar
| ||||||||||||||
| Manual | dplvar |
Syntax
[edit source]- Sets one symbolic variable name and assign a value:
{{#dplvar:set|varname|valueofvar}}
- Sets multiple symbolic variable names and assigns values to them (one after the other):
{{#dplvar:set|name1|value1|name2|value2|..|..}}
- Assigns a value only if the variable is empty / has not been used so far:
{{#dplvar:default|name|value}}
- Returns the current value of the variable:
{{#dplvar:name}}
Example 1
[edit source]Part 1:
This sets a variable, names it "varName", and then assigns the value "My Value" to it.
Note: The result is empty because setting a variable simply assigns a value, it doesn't also display that variable.
{{#dplvar:set|varName|My Value}}
Part 1 Result:
Part 2:
This displays the (already set above) value of the variable called "varName".
{{#dplvar:varName}}
Part 2 Result:
My Value
Example 2
[edit source]Example:
This invokes the {{dplvarUpdate}} template, which initially sets a variable called varName and assigns it the value My Value using:{{#dplvar:set|varName|My Value}}. It later evaluates whether the first parameter is empty or not and if empty returns n/a. If not empty, it gives the revised value My Value2.
{{dplvarUpdate|true}}
Result:
- The initial value of
{{#dplvar:varName}}is: My Value - If the first param is not empty
{{#dplvar:varName}}is: My Value2
Example 3
[edit source]Example:
The first line's statements set the variables initially as: a to x, b to y, and c to <!--empty-->; then the following variables also have a default set: a to aaaa, c to cccc, and d to dddd.
The last four lines display the value of each corresponding variable in a bulleted list format.
{{#dplvar:set|a|x|b|y|c|<!--empty-->}} {{#dplvar:default|a|aaaa}} {{#dplvar:default|c|cccc}} {{#dplvar:default|d|dddd}}
* a: {{#dplvar:a}}
* b: {{#dplvar:b}}
* c: {{#dplvar:c}}
* d: {{#dplvar:d}}
Result:
- a: x
- b: y
- c: cccc
- d: dddd
Notes:
- Variable "c" was set to "cccc" because although it was already set, its note is equivalent to an empty value.
- Variable "d" was set to "dddd" because it was not already set.