Help:Array
This is a copy of the master help page at m:Help:Array. Do not edit this page. Edits will be lost in the next update from the master page. Either edit the master help page for all projects at Meta, or edit the project-specific text at Template:Ph:Array. You are welcome to copy the exact wikitext from the master page at Meta and paste it into this page at any time.
A method to create a data array using templates is as follows. A template, the so-called concatenation template, produces the values of all its parameters. It is called by a data template that assigns all data to the parameters, then erases the values of the parameters of which the names are its own parameters, resulting in erasing all values except the desired one. The root template provides the selection of values to be erased: all parameters are specified for erasure from the list to be displayed, but for the desired one the specification for erasure is itself erased.
Contents |
[edit] Language name example
{{langname|de}} gives Template:Langname:
The "root template"
calls the "data template"
which calls the "concatenation template"
[edit] A 24 by 60 array
A concatenation template for general use, with unnamed parameters 1 - 1440, is Template:Tim.
The root template Template:Tim is for a 2D array of size 24 × 60, with index values "00:00" - "23:59". Thus it can also take a time as index value, in particular the result of {{CURRENTTIME}}.
A second set of index values is used in defining the array elements. These index values may or may not be the same as the first set. In the example above they are the same, here they are not, we have the index values 1 - 1440. Thus the template contains 1440 pieces of code of the form "00:04=5". The template is called with two parameters: the array name (i.e. the name of the data template) and the index pair, e.g. "00:04", which can also be seen as a single index.
A small modification fixes the first (part of the) index to 0: Template:Tim.
A matching example data template is Template:Tim. The first part contains 1440 pieces of code of the form "5=abc". The second part contains 1440 pieces of code of the form "=". This part can be reused for other data arrays with these index values.
Template:Timcnl shows that the first part can contain less than 1440 data, while for the second part this is also the case, and this part may contain more than the first part, for convenient expanding of the array by just adding to the first part.
Examples:
{{array1440|city array demo|00:02}} gives Template:Array1440
{{array1440|city array demo|00:03}} gives Template:Array1440
{{array60|city array demo|02}} gives Template:Array60
Example of using array elements as parameters:
{{t2|{{array60|city array demo|01}}|{{array60|city array demo|02}}}} using Template:Timc gives Template:T2
Examples of using a template result as (or in) an array index:
{{array60|city array demo|{{x2|1}}}} gives Template:Array60.
{{array60|city array demo|{{array60|city array demo|16}}}} gives Template:Array60.
[edit] Plain numbers as index values
{{array|square|3}} using Template:Timcnl and Template:Timcnl and Template:Tim gives Template:Array.
Nested:
{{array|square|{{array|square|2}}}} gives Template:Array.
For larger arrays, extend the three lists: k=k, k=data, {{{k }}}=. The fourth list is already available for 1440 index values.
[edit] Other example
{{array|array demo|3}} using Template:Timcnl and Template:Timcnl and Template:Tim gives Template:Array.
[edit] Comparison with other method
The advantage compared to one of the other methods is that unlike that method, no separate auxiliary template is needed for each value of the index used. This makes copying to another project much easier, especially if no export/import feature is available.
On the other hand, in the method on this page enlarging the array, when no preparation for that has been made in advance, requires updating three templates, while the other method requires updating one and creating one.
[edit] Wikiquote-specific content
[edit] Links to other help pages
| Help contents - all pages in the Help namespace: Meta b: c: n: w: q: wikisource wiktionary
|