Module:Loops/doc
This is the documentation page for Module:Loops
Lua module implementing features similar to mw:Extension:Loops, specifically with functionality to parse lists, since the AE Wiki mainly utilizes the extension for that purpose.
Usage[edit source]
{{#invoke:Loops|function_name}}
Functions[edit source]
parseList
[edit source]
Parses a string list using a given delimiter (defaults to %s if not given). The value is then passed into the specified template or formatted according to a given string format pattern.
Transitioning from Extension:Loops[edit source]
This is documentation on how to transition from using Extension:Loops to Module:Loops to parse lists.
Extension:Loops Syntax
{{#vardefine:count|0}} {{#while: | {{#if: {{#explode:<list>|<delimiter>|{{#var:count}}}} | true }} | <!-- do something --> }}
The key variables here are <list> and <delimiter>. These can simply be specified in the module invoke like so:
{{#invoke: |list=<list> |delimiter=<delimiter> ... }}
The rest of the invoke depends on how complex the "do something"/block statement portion is, you can choose to either use a string format (simple output) or template format (more complex output).
- If your block statement is simple formatting, then use string format output.
- Because of the order the parser runs statements, some Wikitext may not be compatible with string format. Thus it's recommended for more complex Wikitext use template format instead.
- If you use
{{#explode:<list>|<delimiter>|{{#var:count}}}}
inside your block statement, replace it with a replace string of choice. This should be a unique string pattern, as you don't want to erroneously replace other parts of the format string.
- If your block statement is more complex, consider moving it into a template which you can then specify with the module invoke.
- If you use
{{#explode:<list>|<delimiter>|{{#var:count}}}}
inside your block statement, replace it with{{{1|}}}
. - If you use your index/counter variable in your template code, you can replace it with
{{#var:count}}
.
- If you use
See the parseList examples for sample usages.
Usage[edit source]
- Template format
{{#invoke:Loops|parseList |list= |delimiter= |template= |template!<arg>= //optional }}
- String format
{{#invoke:Loops|parseList |list= |delimiter= |format= |replaceString= }}
Examples[edit source]
- Template format
{{#invoke:Loops|parseList |list=Marius "Dream of Thebes",Marius "Dream of Thebes",Marius "Dream of Thebes" |delimiter=, |template=Card icon |template!size=50px |template!text=500 }}
- String format example #1
{{#invoke:Loops|parseList |list=git,gem,fp |delimiter=, |format=|format=<nowiki/> * Test $1 |replaceString=$1 }}
- Test git
- Test gem
- Test fp
- String format example #2
{| class="wikitable" ! Test {{#invoke:Loops|parseList |list=git,gem,fp |delimiter=, |format=<tr><td>$1 in a cell</td></tr> |replaceString=$1 }} |}
Test |
---|
git in a cell |
gem in a cell |
fp in a cell |
numElements
[edit source]
Returns the number of elements in a string list given a delimiter (defaults to %s if not given).
Usage[edit source]
{{#invoke:Loops|numElements |list= |delimiter= }}
Example[edit source]
{{#invoke:Loops|numElements |list=this,list,has,5,elements |delimiter=, }}
5
loop
[edit source]
Duplicates the mw:Extension:Loop##loop function. Output can either be a given template or string format.
Usage[edit source]
{{#invoke:Loops|loop |startValue= |numLoops= |template= |template!<arg>= //optional }}
- String format
{{#invoke:Loops|parseList |startValue= |numLoops= |format= |replaceString= //optional }}
Example[edit source]
- Template format
{{#invoke:Loops|loop |startValue=3 |numLoops=5 |template=Text |template!style=border: 1px solid black; }}
Lua error: expandTemplate: template "Text" does not exist.
- String format
{{#invoke:Loops|loop |startValue=8 |numLoops=3 |format=<nowiki/> * Test $1 |replaceString=$1 }}
- Test 8
- Test 9
- Test 10