Template:Array/doc: Difference between revisions

From Honkai: Nexus Anima Wiki
Jump to navigation Jump to search
Kwwxis (talk | contribs)
Created page with "{{Documentation/Header}} {{High risk}} {{Lua|Array}} 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 <code>separator</code> parameter. *'''2''': separator - the character or substring to split on. ** <code>{newline}</code> is replaced with a newline. ** <code>{space}</code> is replaced with a space. '''Format Parameters:'''<br /> If format is..."
 
mNo edit summary
Line 1: Line 1:
{{Documentation/Header}}
{{Documentation/Header}}
{{High risk}}
{{High Risk}}
{{Lua|Array}}
{{Lua|Array}}
Divides a string into a formatted list of substrings.
Divides a string into a formatted list of substrings.

Revision as of 21:24, 29 August 2025

This is the documentation page for Array.
It contains usage information, categories, and other content not part of the original template page.
This template is used on 1,042 pages, or on about 35.33% of all pages.
Edits to this template will be widely noticed. To avoid large-scale disruption and unnecessary server load, any changes to this template should be tested in its sandbox or testcases subpages, or in your own user space. The tested changes can then be added to this page in one single edit.
Please consider discussing any changes in the wiki's Discord.
This template uses Module:Array, a script written in Lua.

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 separator parameter.
  • 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 &nbsp;
  • format<index>: custom format to override the format param for a particular substring by its index
    • Index is 1-based. For example format2 would be the format for the second item of the array.
    • supports the same tokens (like {itemLink}) that format param does.
  • 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 &nbsp;
  • 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
  • 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=1 but this is a shortcut.
  • 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}}}}

VentiVentiJeanJeanDilucDiluc

Template in format example 2
{{Array|Venti;Jean;Diluc|;|²{Character¦{item}¦50}²|template=1}}

VentiVentiJeanJeanDilucDiluc

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.

Template parameters

ParameterDescriptionTypeStatus
Array String1

The input string, each item expected to be separated by the "separator" parameter.

Example
Item 1;Item 2;Item 3
Stringrequired
Separator2 sep separator

The character or substring to split on.

Example
;
Stringrequired
Format3 format

The resulting format of each substring. See the template documentation page for more info.

Stringrequired
Join4 join

The separator between each element to join.

Default
(no separator)
Stringoptional
Join as sentencesentence

Set to 1 to format as a sentence (commas with an "and" for the last element).

Default
0
Booleanoptional
First item onlyfirstItemOnly

Set to 1 to only display the first element of the array.

Default
0
Booleanoptional
Sortsort

Set to 1 to sort the items in the array in ascending order, -1 for descending.

Numberoptional
Dedupe?dedupe

Set to 1 to remove duplicate items in the array.

Booleanoptional
Remove Empty ItemsremoveEmpty

Set to 1 to remove empty elements.

Booleanoptional
Offset StartoffsetStart

Only keep elements of the array at and after this index.

Numberoptional
Offset EndoffsetEnd

Only keep elements of the array at and before this index.

Numberoptional