|
|
| Line 1: |
Line 1: |
| [[Template:for]] ([[Template talk:for|talk]], [[Special:Whatlinkshere/Template:for|backlinks]], [http://meta.wikimedia.org
| | {{documentation subpage}} |
| | |
| Uses [[Template:for/aux]] ([[Template talk:for/aux|talk]], [[Special:Whatlinkshere/Template:for/aux|backlinks]], [http://meta.wikimedia.org{{localurl:Template:for/aux|action=edit}} edit])
| |
| | |
| == Description == | | == Description == |
| The template calls a specified template up to 150 times, where one parameter takes each of a list of values; in addition to the variable parameter, for up to 4 parameters a fixed value can be specified. | | The template calls a specified template up to 150 times, where one parameter takes each of a list of values; in addition to the variable parameter, for up to 4 parameters a fixed value can be specified. |
| Line 22: |
Line 19: |
| </pre> | | </pre> |
|
| |
|
| ==Examples== | | == Examples == |
| {| class="wikitable", border=1 | | {| class="wikitable", border=1 |
| !Code | | !Code |
| Line 59: |
Line 56: |
|
| |
|
| Note that the last part of the separator is used as a prefix; the first prefix needs to be put separately. | | Note that the last part of the separator is used as a prefix; the first prefix needs to be put separately. |
|
| |
| ----
| |
|
| |
| <nowiki>{{for|a|3||c|call=x3|sep=-}}</nowiki> using {{tim|x3}} gives
| |
| :{{for|a|3||c|call=x3|sep=-}}
| |
|
| |
| ----
| |
|
| |
| <nowiki>{{for|p|||3||c|call=t|sep=///}}</nowiki> using {{tim|t}} gives
| |
| :{{for|p|||3||c|call=t|sep=///}}
| |
|
| |
| ----
| |
|
| |
| <nowiki>{{for|call=short DOW|3|1|5|3|2|sep=&nbsp;/&nbsp;}}</nowiki> using {{tim|short DOW}} gives
| |
| :{{for|call=short DOW|3|1|5|3|2|sep= / }}
| |
|
| |
| ----
| |
|
| |
| <nowiki>{{for|call=t2|pc1=2=constant|abc|def|ghi}}</nowiki> using {{tim|t2}} gives:
| |
|
| |
| {{for|call=t2|pc1=2=constant|abc|def|ghi}}
| |
|
| |
| ----
| |
|
| |
| <nowiki>{{for|call=concat and link to w:en:|sep=,&nbsp;|pc1=John_|pv=2||Lennon|Wayne}}
| |
| </nowiki> using {{timc|concat and link to w:en:}} gives {{for|call=concat and link to w:en:|sep=, |pc1=John_|pv=2||Lennon|Wayne}}
| |
|
| |
| A for-call can give a row or column of choice, e.g. using {{tim|power}}:
| |
|
| |
| <nowiki>{{for|sep=,|2|3|call=power|prefix=2,}}</nowiki> gives {{for|sep=,|2|3|call=power|prefix=2,}}
| |
|
| |
| <nowiki>{{for|sep=,|2|3|call=power|prefix=3,}}</nowiki> gives {{for|sep=,|2|3|call=power|prefix=3,}}
| |
|
| |
| <nowiki>{{for|sep=,|2|3|call=power|postfix=,2}}</nowiki> gives {{for|sep=,|2|3|call=power|postfix=,2}}
| |
|
| |
| <nowiki>{{for|sep=,|2|3|call=power|postfix=,3}}</nowiki> gives {{for|sep=,|2|3|call=power|postfix=,3}}
| |
|
| |
|
| |
| ----
| |
|
| |
| A constant parameter is ignored if it is the same as the (implicitly or explicitly given) variable parameter:
| |
|
| |
| <nowiki>{{for|call=t2|pc1=1=7|pc2=2=5|abc|def|ghi|sep=,}}</nowiki> using {{tim|t2}} gives:
| |
|
| |
| {{for|call=t2|pc1=1=7|pc2=2=5|abc|def|ghi|sep=,}}
| |
|
| |
| ----
| |
|
| |
| <nowiki>{{for|sep=,|call=x3|1=a=b|2=c=d|3=e}}</nowiki> gives
| |
| {{for|sep=,|call=x3|1=a=b|2=c=d|3=e}}
| |
|
| |
| ----
| |
|
| |
| <nowiki>{{#expr:{{for|call=plus square|pv=1|1|2|3|4|5}}}}</nowiki> gives {{#expr:{{for|call=plus square|pv=1|1|2|3|4|5}}}}.
| |
|
| |
| Semi-recursive: see [[Template talk:Foreach/recursion]]
| |
|
| |
| ===[[Help:Table|Table]]s===
| |
| XML:
| |
|
| |
| <pre>
| |
| <table border=1>
| |
| <tr><td>{{for|call=X1|3|1|5|3|2|sep=</td><td>}}</td></tr>
| |
| <tr><td>{{for|call=square|3|1|5|3|2|sep=</td><td>}}</td></tr>
| |
| </table>
| |
| </pre>
| |
| gives
| |
| <table border=1>
| |
| <tr><td>{{for|call=X1|3|1|5|3|2|sep=</td><td>}}</td></tr>
| |
| <tr><td>{{for|call=square|3|1|5|3|2|sep=</td><td>}}</td></tr>
| |
| </table>
| |
| ----
| |
| HTML:
| |
|
| |
| <pre>
| |
| <table border=1>
| |
| <tr><td>{{for|call=X1|3|1|5|3|2|sep=<td>}}
| |
| <tr><td>{{for|call=square|3|1|5|3|2|sep=<td>}}
| |
| </table>
| |
| </pre>
| |
| gives
| |
| <table border=1>
| |
| <tr><td>{{for|call=X1|3|1|5|3|2|sep=<td>}}
| |
| <tr><td>{{for|call=square|3|1|5|3|2|sep=<td>}}
| |
| </table>
| |
| ----
| |
| Wikitable:
| |
|
| |
| <pre>
| |
| {| border=1
| |
| |-
| |
| |{{for|call=X1|3|1|5|3|2|sep={{!!}}}}
| |
| |-
| |
| |{{for|call=square|3|1|5|3|2|sep={{!!}} }}
| |
| |}
| |
| </pre>
| |
| gives
| |
| {| border=1
| |
| |-
| |
| |{{for|call=X1|3|1|5|3|2|sep={{!!}}}}
| |
| |-
| |
| |{{for|call=square|3|1|5|3|2|sep={{!!}} }}
| |
| |}
| |
| ----
| |
| XML:
| |
|
| |
| <pre>
| |
| <table border=1>
| |
| <tr><td>{{for|call=table row example|3|1|5|3|2|sep=</td></tr><tr><td>|pc1=sep1=</td><td>}}
| |
| </table>
| |
| </pre>
| |
| gives
| |
| <table border=1>
| |
| <tr><td>{{for|call=table row example|3|1|5|3|2|sep=</td></tr><tr><td>|pc1=sep1=</td><td>}}
| |
| </table>
| |
| ----
| |
| HTML:
| |
|
| |
| <pre>
| |
| <table border=1>
| |
| <tr><td>{{for|call=table row example|3|1|5|3|2|sep=<tr><td>|pc1=sep1=<td>}}
| |
| </table>
| |
| </pre>
| |
| gives
| |
| <table border=1>
| |
| <tr><td>{{for|call=table row example|3|1|5|3|2|sep=<tr><td>|pc1=sep1=<td>}}
| |
| </table>
| |
| ----
| |
| Wikitable:
| |
|
| |
| <pre>
| |
| {| border=1
| |
| |-
| |
| |{{for|call=table row example|3|1|5|3|2|sep=&nbsp;
| |
| {{!}}-
| |
| {{!}}|pc1=sep1={{!!}}}}
| |
| |}
| |
| </pre>
| |
| gives
| |
| {| border=1
| |
| |-
| |
| |{{for|call=table row example|3|1|5|3|2|sep=
| |
| {{!}}-
| |
| {{!}}|pc1=sep1={{!!}}}}
| |
| |}
| |
|
| |
| ----
| |
| Wikitable sortable:
| |
| <pre>
| |
| {| class="wikitable sortable"
| |
| |-
| |
| !number!!square
| |
| |-
| |
| |{{for|call=table row example|3|1|5|3|2|sep=
| |
| {{!}}-
| |
| {{!}}|pc1=sep1={{!!}}}}
| |
| |}
| |
| </pre>
| |
| gives
| |
| {| class="wikitable sortable"
| |
| |-
| |
| !number!!square
| |
| |-
| |
| |{{for|call=table row example|3|1|5|3|2|sep=
| |
| {{!}}-
| |
| {{!}}|pc1=sep1={{!!}}}}
| |
| |}
| |
|
| |
|
| |
|
| |
| ==Substitution==
| |
| Substitution through [[Template:For/aux]] works also, as follows:
| |
|
| |
| <nowiki>{{subst:for|a|3||c|call=x3|sep=-|subst=subst:}}</nowiki> using {{tim|x3}} gives:
| |
|
| |
| {{x3|=|=|=|=|{{{pv|1}}}={{{prefix|}}}a{{{postfix|}}}}}-{{x3|=|=|=|=|{{{pv|1}}}={{{prefix|}}}3{{{postfix|}}}}}-{{x3|=|=|=|=|{{{pv|1}}}={{{prefix|}}}{{{postfix|}}}}}-{{x3|=|=|=|=|{{{pv|1}}}={{{prefix|}}}c{{{postfix|}}}}}
| |
|
| |
| [[Special:ExpandTemplates]] gives full substitution.
| |
|
| |
| ==Notes==
| |
| *Empty parameter values work in the regular way, they are ''not'' ignored like undefined ones.
| |
| *"=" in parameter values is allowed.
| |
|
| |
| ==See also==
| |
| *{{tim|foreach}}
| |
| *{{tim|tblb}}
| |
| *[[Help:Parameter default]]
| |
| *[[Help:Array]]
| |
| *[[mw:Extension:LoopFunctions]]
| |
Description
The template calls a specified template up to 150 times, where one parameter takes each of a list of values; in addition to the variable parameter, for up to 4 parameters a fixed value can be specified.
Usage
{{for
|call=template to call
|sep=what to separate the entries with
|pc1=parameter name=constant value
|pc2=parameter name=constant value
|pc3=parameter name=constant value
|pc4=parameter name=constant value
|pv=name of variable parameter
|prefix=constant first part of the value of pv
|postfix=constant last part of the value of pv
|list of up to 150 parameter values (without prefixes and postfixes), with separator "|"
}}
Examples
| Code
|
Result
|
1{{for
|00|01|02|03|04|05|06|07|08|09
|10|11|12|13|14|15|16|17|18|19
|20|21|22|23|24|25|26|27|28|29
|30|31|32|33|34|35|36|37|38|39
|40|41|42|43|44|45|46|47|48|49
|50|51|52|53|54|55|56|57|58|59
|60|61|62|63|64|65|66|67|68|69
|70|71|72|73|74|75|76|77|78|79
|80|81|82|83|84|85|86|87|88|89
|90|91|92|93|94|95|96|97|98|99
|call=x1
|sep=, 1
}}
|
1Lua error: expandTemplate: template "x1" does not exist.
|
Note that the last part of the separator is used as a prefix; the first prefix needs to be put separately.