Extension:ArrayFunctions/FAQ

How can I define an array to be used throughout a page?

edit

It is not possible to directly define an array to be used throughout a page, because this would require sequential processing of extension tags, which is not supported by Parsoid (see Parsoid/Extension API#No support for sequential, in-order processing of extension tags). Instead, you can pass arrays around as template parameters:

{{My template|{{#af_list:a|b|c}}}}

This way, the array is available in Template:My template as {{{1}}}.

How to iterate over an array?

edit

It is possible to iteratively access elements of an array using #af_foreach:

{{#af_foreach:{{#af_list:red|green|blue}}||color|<nowiki/>
* {{{color}}} is my favourite.
}}

The expected output from the snipped above is:

  • red is my favourite.
  • green is my favourite.
  • blue is my favourite.

Why are values not recognized as arrays?

edit

This may happen because your arrays are too large. MediaWiki internally keeps a counter on the total size of template arguments, which can be increased by increasing $wgMaxArticleSize.

How is this different from extensions such as Arrays or Variables?

edit

The main difference between ArrayFunctions and those extensions is that ArrayFunctions parser functions are pure. This means that instead of modifying or declaring a variable, the parser function directly outputs its result.

For example with #af_map, the given array is not modified; instead, a copy is created, modified and then outputted. No parser function in ArrayFunctions modifies global state: all computation happens solely with the invocation of the parser function. This makes working with ArrayFunctions very different from working with other extensions such as Arrays or Variables. Instead of imperatively modifying an array stored in a variable, function composition must be used to perform more complex operations. For example:

Arrays
{{#arraydefine: fruits | orange, banana, strawberry, apple }}
{{#arraysort: fruits | asc }}
{{#arrayprint: fruits }}
ArrayFunctions
{{#af_print: 
    {{#af_sort: 
        {{#af_list: orange | banana | strawberry | apple }}
    }}
}}

Why is whitespace trimmed from array values?

edit

Whitespace is inherently implicit in wikitext. In order to be consistent with this behaviour, whitespace is recursively trimmed from array values.