Template:Array/doc: Difference between revisions
mNo edit summary |
No edit summary |
||
| Line 71: | Line 71: | ||
;Template in format example 1 | ;Template in format example 1 | ||
<pre>{{Array|Venti;Jean;Diluc|;|{{Character|{item}|50}}}}</pre> | <pre>{{Array|Venti;Jean;Diluc|;|{{Character|{item}|50}}}}</pre> | ||
{{Array| | {{Array|Nanafey;Kiana;Blade|;|{{Character|{item}|50}}}} | ||
;Template in format example 2 | ;Template in format example 2 | ||
<pre>{{Array|Venti;Jean;Diluc|;|²{Character¦{item}¦50}²|template=1}}</pre> | <pre>{{Array|Venti;Jean;Diluc|;|²{Character¦{item}¦50}²|template=1}}</pre> | ||
{{Array| | {{Array|Nanafey;Kiana;Blade|;|^2{Character¦{item}¦50}^2|template=1}} | ||
;Multi-character separator example | ;Multi-character separator example | ||
Latest revision as of 20:12, 31 August 2025
This is the documentation page for Array. It contains usage information, categories, and other content not part of the original template page. | ||
|---|---|---|
| Main | Documentation | Usage |
Divides a string into a formatted list of substrings.
Syntax
Required Parameters:
- 1: arrayString - the input string, each item expected to be separated by the
separatorparameter. - 2: separator - the character or substring to split on.
{newline}is replaced with a newline.{space}is replaced with a space.
Format Parameters:
If format is not specified, then the default format is {item}.
- 3: format - the resulting format of each substring.
{item}is replaced with the item.{itemLink}is replaced with the item as a link.{itemLinkSafe}is replaced with the item as a link if the page exists otherwise is replaced with the item as text.{index}is replaced with the index.{newline}is replaced with a newline.{space}is replaced with a space. Useful if you need a leading/trailing space. You could also use
- format<index>: custom format to override the
formatparam for a particular substring by its index- Index is 1-based. For example
format2would be the format for the second item of the array. - supports the same tokens (like
{itemLink}) thatformatparam does.
- Index is 1-based. For example
- noTrim (optional): set to 1 to not remove whitespace from items in the array.
- template (optional): set to 1 to allow escaped template syntax for complex returns
- escape {{ as: ²{ or ^2{.
- escape }} as: }² or }^2.
- escape | as: ¦ or ¹.
Join Parameters:
These three parameters are mutually exclusive (meaning you can only have one of these three):
- 4: join (optional) - separator between each element to join. Default no separator.
{newline}is replaced with a newline.{space}is replaced with a space. Useful if you need a leading/trailing space. You could also use
- sentence (optional): set to 1 to format as a sentence (commas with an "and" for the last element).
- sentence_join (optional): sentence join character, defaults to
, - sentence_last (optional): sentence join last word, defaults to
and
- sentence_join (optional): sentence join character, defaults to
- prefix (optional): Text added to start of result.
- suffix (optional): Text added to end of result.
Filter/Sort Parameters:
These parameters are checked/applied in the order as shown below:
- removeEmpty (optional): set to 1 to remove empty elements.
- dedupe (optional): set to 1 to remove duplicate items in the array.
- sort (optional): set to 1 to sort the items in the array in ascending order, -1 for descending.
- firstItemOnly (optional): set to 1 to only display the first element of the array.
- You could also do
offsetStart=1|offsetEnd=1but this is a shortcut.
- You could also do
- offsetStart (optional): only keep elements of the array at and after this index (inclusive).
- offsetEnd (optional): only keep elements of the array at and before this index (inclusive).
Knowing this order, you can use these parameters to achieve various effects. Such as: removeEmpty=1|offsetStart=1|offsetEnd=1 to get the first non-empty element of the input array string.
Examples
- Simple example
{{Array|1,2,3,4,5|,|*''{item}''|{newline} }}
- 1
- 2
- 3
- 4
- 5
- Dedupe example
{{Array|1,2,2,2,3,4,5|,|*''{item}''|{newline}|dedupe=1}}
- 1
- 2
- 3
- 4
- 5
- Remove empty example
{{Array|1,2,,, ,3,4,5|,|*''{item}''|{newline}|removeEmpty=1}}
- 1
- 2
- 3
- 4
- 5
- Sort example
{{Array|Oranges;Apples;Bananas;Mangos;Blueberries|;|*{item}|{newline}|sort=1}}
- Apples
- Bananas
- Blueberries
- Mangos
- Oranges
- Template in format example 1
{{Array|Venti;Jean;Diluc|;|{{Character|{item}|50}}}}
- Template in format example 2
{{Array|Venti;Jean;Diluc|;|²{Character¦{item}¦50}²|template=1}}
- Multi-character separator example
{{Array|a&&b&&c&&d&&e|&&|{index}: {item}|,{space} }}
1: a, 2: b, 3: c, 4: d, 5: e
- Sentence example
{{Array|Oranges;Apples;Bananas;Mangos;Blueberries|;|{item}|sentence=1}}
Oranges, Apples, Bananas, Mangos, and Blueberries
- First item only example
{{Array|Oranges;Apples;Bananas;Mangos;Blueberries|;|{item}|firstItemOnly=1}}
Oranges
- Offset start and end examples
{{Array|A,B,C,D,E,F,G,H,I,J,K|,|{item}|join=,{space}|offsetStart=2}}
B, C, D, E, F, G, H, I, J, K
{{Array|A,B,C,D,E,F,G,H,I,J,K|,|{item}|join=,{space}|offsetStart=2|offsetEnd=5}}
B, C, D, E
{{Array|A,B,C,D,E,F,G,H,I,J,K|,|{item}|join=,{space}|offsetStart=2|offsetEnd=2}}
B
{{Array|A,B,C,D,E,F,G,H,I,J,K|,|{item}|join=,{space}|offsetStart=2|offsetEnd=-2}}
B, C, D, E, F, G, H, I
{{Array|A,B,C,D,E,F,G,H,I,J,K|,|{item}|join=,{space}|offsetStart=-2}}
J, K
{{Array|A,B,C,D,E,F,G,H,I,J,K|,|{item}|join=,{space}|offsetStart=-1}}
K
- Item Specific Format
{{Array|Item A,Item B,Item C|,|*''{item}''|{newline} |format2=*Item 2 specific format: '''{item}'''}}
- 1
- Item 2 specific format: 2
- 3
- 4
- 5
Template Data
Divides a string into a formatted list of substrings.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Array String | 1 | The input string, each item expected to be separated by the "separator" parameter.
| String | required |
| Separator | 2 sep separator | The character or substring to split on.
| String | required |
| Format | 3 format | The resulting format of each substring. See the template documentation page for more info. | String | required |
| Join | 4 join | The separator between each element to join.
| String | optional |
| Join as sentence | sentence | Set to 1 to format as a sentence (commas with an "and" for the last element).
| Boolean | optional |
| First item only | firstItemOnly | Set to 1 to only display the first element of the array.
| Boolean | optional |
| Sort | sort | Set to 1 to sort the items in the array in ascending order, -1 for descending. | Number | optional |
| Dedupe? | dedupe | Set to 1 to remove duplicate items in the array. | Boolean | optional |
| Remove Empty Items | removeEmpty | Set to 1 to remove empty elements. | Boolean | optional |
| Offset Start | offsetStart | Only keep elements of the array at and after this index. | Number | optional |
| Offset End | offsetEnd | Only keep elements of the array at and before this index. | Number | optional |