Template talk:Fors

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

Template:fors (talk, backlinks, edit) containing:


{{fors/aux |v@= |c={{{call}}} |pv={{{pv|1}}} |s={{{sep|}}} |pc1={{{pc1|=}}} |pc2={{{pc2|=}}} |pc3={{{pc3|=}}} |pc4={{{pc4|=}}}| 1={{{1|@}}}|2={{{2|@}}}|3={{{3|@}}} }}


containing:

Template:fors/aux (talk, backlinks, edit) containing:


{{{v{{{1}}}|{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{1}}}}}}}}{{{v{{{2}}}|{{{s}}}{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{2}}}}}}}}{{{v{{{3}}}|{{{s}}}{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{3}}}}}}}}


Documentation[edit]

Description[edit]

The template calls a specified template up to 3 times, where one parameter takes each of a list of values; surplus values are ignored; in addition to the variable parameter, for up to 4 parameters a fixed value can be specified.

Usage[edit]

{{fors
  |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
  |list of up to 150 parameter values, with separator "|"
}}

Examples[edit]

{{fors|sep=,|call=x3|1=a=b|2=c=d|3=e}} gives a=ba=ba=b,c=dc=dc=d,eee

Code Result
1{{fors
|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
}}
100, 101, 102

Note that the last part of the separator is used as a prefix; the first prefix needs to be put separately.

{{fors|a|3||c|call=x3|sep=-}} using Template:X3 gives

aaa-333-

{{fors|p|||3||c|call=t|sep=///}} using Template:T gives

start-p-end///start--end///start--end

{{fors|call=short DOW|3|1|5|3|2|sep= / }} using Template:Short DOW gives

Wed / Mon / Fri

{{fors|call=t2|pc1=2=constant|abc|def|ghi}} using Template:T2 gives:

parameter 1 is "abc", parameter 2 is "="parameter 1 is "def", parameter 2 is "="parameter 1 is "ghi", parameter 2 is "="

A constant parameter is ignored if it is the same as the (implicitly or explicitly given) variable parameter:

{{fors|call=t2|pc1=1=7|pc2=2=5|abc|def|ghi|sep=,}} using Template:T2 gives:

parameter 1 is "abc", parameter 2 is "2=5",parameter 1 is "def", parameter 2 is "2=5",parameter 1 is "ghi", parameter 2 is "2=5"

Semi-recursive: see Template talk:Foreach/recursion

A reserved name that cannot be used as list item is "@"; it is ignored, but e.g. @1 is not:

{{for|a|@|@1|b|c|call=x3|sep=-}} gives

@@@a@1@1@1abbbaccc

Related templates[edit]

This template is a short version of Template:For, with improvement, see first example.

Discussion[edit]