0

As far as I understand, the following function:

{{mytemplate|foo|bar|snakes|boat|programming}}

has the following parameters automatically filled for it:

{{mytemplate|1=foo|2=bar|3=snakes|4=boat|5=programming}}

How does the following function autofill when some numbers are defined for it:

{{mytemplate|2=foo|bar|snakes|param=boat|3=programming}}

with param= being equivalent to 1=?


Backstory:

I'm writing a string function that will allow a user to extract parameter arguments from a mediawiki function. I have a mediawiki server installed; if this is possible to do via the API, that would work too in solving my issue. Basically I need a stringlist containing all parameters and their corresponding arguments.

Anon
  • 2,267
  • 3
  • 34
  • 51

2 Answers2

2

No, param=boat means that you have parameter param with value boat, and 2=foo means that parameter 2 has value foo. So, any other values which are free (with undefined parameters) are for the missing number parameters, which means that in your example:

{{mytemplate
|2=foo
|bar                //1=bar
|snakes             //4=snakes (because 2 and 3 are already taken)
|param=boat
|3=programming
}}

Or in your template you need to use: {{{param}}}, {{{1}}}, {{{2}}}, {{{3}}} and {{{4}}}.

Termininja
  • 6,620
  • 12
  • 48
  • 49
  • So... parameters are not automatically indexed? Sorry; I find your answer confusing. :) – Anon Feb 18 '16 at 10:50
  • 1
    Of course, `param` will not be indexed. This is not array, you can put `param` (or some other value which is assigned to some parameter) on any place in the template. Only values without parameters will be indexed automatically. – Termininja Feb 18 '16 at 13:25
  • 1
    After some experimentation, it appears that the values without parameters will left to right, be indexed as 1, 2, 3, 4... without skipping integers, regardless of whether their named parameter has already been specified. The right most parameters will override the left. – Anon Feb 18 '16 at 13:30
2

If this is possible to do via the API, that would work too in solving my issue.

Yes, you can use the parse API with parameters text and prop=parsetree.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375