Extension talk:VariablesExtension
From MediaWiki.org
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).
Contents |
[edit] Variables and Conditional Parser Functions
It must be noted that everything in conditionals gets executed (though only one result gets displayed). Because of this, every instance of #vardefine will always get executed, regardless of to what the conditional gets evaluated.
Given the following:
{{#vardefine:variable|value}}{{
#ifeq:
{{#var:variable}}|
value|
{{#vardefine:variable|nextvalue}}|
{{#vardefine:variable|prevvalue}}
}}
{{#var:variable}} gives prevvalue.
Instead you have to nest the conditional inside #vardefine:
{{#vardefine:variable|value}}{{
#vardefine:variable|
{{#ifeq:
{{#var:variable}}|
value|
nextvalue|
prevvalue
}}
}}
In this case, {{#var:variable}} gives nextvalue.
—Sledged 16:12, 24 October 2006 (UTC)
[edit] Multiple assignments
It would be good if this extension allowed multiple assignments. Say I have a template data that contains a=1|b=2 . I call {{usedata|data}} and usedata gets one template-variable, a, with value 1|b=2. If I could make data say a=1,b=2 and usedata could call variablesextension to set both variables at once, that would be useful.--201.216.136.95 18:24, 10 January 2007 (UTC)
[edit] Bugzilla request
The bug requesting this to be added for the big sites (wikipedia, etc.) is bugzilla:8570. If you really want these functions, go (register and) vote for that bug. If you have an concern, that bug would also be an appropriate place to express it.--201.216.136.95 18:24, 10 January 2007 (UTC)
[edit] MediaWiki version 1.9
How is the compability with MediaWiki version 1.9?
Note that the above conversation may have been edited or added to since the transfer. If in doubt, check the edit history.
[edit] use of undefined variables
Sometimes you want to use a variable which has not been set before and you expect it to return an empty string. I suggest to change the code of function "varf" as follows:
function varf( &$parser, $expr = '' ) {
if (isset($this->mVariables) && array_key_exists($expr,$this->mVariables)) return $this->mVariables[$expr];
return '';
}
- 84.58.192.102 09:11, 28 January 2008 (UTC)
[edit] Number incrementing through page
I'm trying to write a template, two templates in fact, that will increment a number through a page, ie.
{{@@}}
{{@}}
{{@}}
{{@}}
{{@@}}
{{@}}
{{@}}
@@ starts the counter at 1 and prints it and @ increments the number and prints it.
I expect the following to appear:
1 2 3 4 1 2 3
But I get the following:
1 2 2 2 1 2 2
I'm using the following code for the templates.
Template: @@
{{#vardefine:n|1}}{{#var:n}}
Template: @
{{#vardefine:n | {{#expr:{{#var:n}} + 1}}}}{{#var:n}}
Thanks.
--Wahooney 14:05, 11 April 2008 (UTC)
- Your problem is that variables don't persist across templates, so you need to pass the value of n from @@ to @. So, your page needs to be:
{{@@}}
{{@|{{#var:n}}}}
{{@|{{#var:n}}}}
{{@|{{#var:n}}}}
{{@@}}
{{@|{{#var:n}}}}
{{@|{{#var:n}}}}
- --Snuck 05:31, 15 April 2008 (UTC)
- On a 1.12 version of MediaWiki, I get 1 2 3 4 1 5 6 which is not what was expected, but:
{{@@|{{#var:n}}}}
{{@|{{#var:n}}}}
{{@|{{#var:n}}}}
{{@|{{#var:n}}}}
{{@@|{{#var:n}}}}
{{@|{{#var:n}}}}
{{@|{{#var:n}}}}
gives (to me): 1 2 3 4 1 2 3 . --Nbrouard 14:38, 25 June 2008 (UTC)
{{@@|}}
{{@|}}
{{@|}}
{{@|}}
{{@@|}}
{{@|}}
{{@|}}
is also working with the new parser. --Nbrouard 15:14, 26 June 2008 (UTC)
[edit] Multiple inclusions in a template, still counting
Let funcone be the following template:
{{@|}}
{{@|}}
{{@|}}
{{@|}} Inclusion of content
{{{content}}}
Redefining n for second inclusion
{{#vardefine: n|36}}
{{@|}}
{{@|}}
Second inclusion of content
{{{content}}}
after second content
Trying on the following wiki text:
Testing Funcone
{{@@|}}
{{funcone|content=
{{@|}}
{{@|}}
{{@|}}
{{@|}}
{{@|}}
}}
{{@|}}
I get:
- Testing Funcone 1 2 3 4 5 Inclusion of content 6 7 8 9 10 Redefining n for second inclusion
- 37 38 Second inclusion of content 6 7 8 9 10 after second content 39
instead of:
- Testing Funcone 1 2 3 4 5 Inclusion of content 6 7 8 9 10 Redefining n for second inclusion
- 37 38 Second inclusion of content 39 40 41 42 43 after second content 44
Any idea to make substitution earlier? --Nbrouard 13:10, 30 June 2008 (UTC)
[edit] Complications
The wiki I work on is on the brink of updating from 1.11 to 1.13 (two days from now). We use a huge number of variables, mostly so we can get data in and out of templates. Some of our templates set many variables meanwhile other templates utilize multiple dynamic variables. We use the variables and templates to centralize information and make editing easier on the user. They can utilize a template that accesses many variables and not have to deal with the very ugly logistics of where the data is coming from.
If you need some examples:
- http://wiki.secondlife.com/wiki/Template:LSL_Param - Variable parameters get floating text by taking the variable name and plucking the description from memory. The user need not know where the information is to have it accessible.
- http://wiki.secondlife.com/wiki/Template:LSL_Constants/PrimitiveParams - Utilizes a huge number of templates to set the values of a huge number of variables, the end result is a table and many additional variables that have accumulated in the process.
- http://wiki.secondlife.com/wiki/llSetPrimitiveParams utilizes the previous templates, the actual source of this articles is very light compared to what it is actually doing for the articles.
What can I do so that I literally don't have to rework 50 to 100 templates and thousands of articles? -- BlindWanderer 21:54, 21 October 2008 (UTC)

