Template talk:For

頁面內容唔支援其他語言。
出自維基百科,自由嘅百科全書
{{for/aux
  |v@=
  |c={{{call}}}
  |pv={{{pv|1}}}
  |prefix={{{prefix|}}}
  |postfix={{{postfix|}}}
  |s={{{sep|}}}
  |pc1={{{pc1|=}}}
  |pc2={{{pc2|=}}}
  |pc3={{{pc3|=}}}
  |pc4={{{pc4|=}}}|
1={{{1|@}}}|2={{{2|@}}}|3={{{3|@}}}|...|150={{{150|@}}}
}}

Documentation[編輯]

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
}}
1
  想搵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」。

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


{{for|a|3||c|call=x3|sep=-}} using Template:x3 (talk, backlinks, edit) gives

  想搵a,請睇「3」。

{{for|p|||3||c|call=t|sep=///}} using Template:t (talk, backlinks, edit) gives

  想搵p,請睇「For (搞清楚)」。

{{for|call=short DOW|3|1|5|3|2|sep= / }} using Template:short DOW (talk, backlinks, edit) gives

  想搵3,請睇「1」、「5」、「3」同「2」。

{{for|call=t2|pc1=2=constant|abc|def|ghi}} using Template:t2 (talk, backlinks, edit) gives:

  想搵abc,請睇「def」同「ghi」。

{{for|call=concat and link to w:en:|sep=, |pc1=John_|pv=2||Lennon|Wayne}} using Template:Timc gives 錯誤:冇提供內容參數。用 {{other uses}} 喺『other uses』頭解。 (help).

A for-call can give a row or column of choice, e.g. using Template:power (talk, backlinks, edit):

{{for|sep=,|2|3|call=power|prefix=2,}} gives

  想搵2,請睇「3」。

{{for|sep=,|2|3|call=power|prefix=3,}} gives

  想搵2,請睇「3」。

{{for|sep=,|2|3|call=power|postfix=,2}} gives

  想搵2,請睇「3」。

{{for|sep=,|2|3|call=power|postfix=,3}} gives

  想搵2,請睇「3」。



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

{{for|call=t2|pc1=1=7|pc2=2=5|abc|def|ghi|sep=,}} using Template:t2 (talk, backlinks, edit) gives:

  想搵abc,請睇「def」同「ghi」。

{{for|sep=,|call=x3|1=a=b|2=c=d|3=e}} gives

  想搵a=b,請睇「c=d」同「e」。

{{#expr:{{for|call=plus square|pv=1|1|2|3|4|5}}}} gives 表達錯: 未預料嘅 < 運算符.

Semi-recursive: see Template talk:Foreach/recursion

Tables[編輯]

XML:

<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>

gives

  想搵3,請睇「1」、「5」、「3」同「2」。
  想搵3,請睇「1」、「5」、「3」同「2」。

HTML:

<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>

gives

  想搵3,請睇「1」、「5」、「3」同「2」。
  想搵3,請睇「1」、「5」、「3」同「2」。

Wikitable:

{| border=1
|-
|{{for|call=X1|3|1|5|3|2|sep={{!!}}}}
|-
|{{for|call=square|3|1|5|3|2|sep={{!!}} }}
|}

gives

  想搵3,請睇「1」、「5」、「3」同「2」。
  想搵3,請睇「1」、「5」、「3」同「2」。

XML:

<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>

gives

  想搵3,請睇「1」、「5」、「3」同「2」。

HTML:

<table border=1>
<tr><td>{{for|call=table row example|3|1|5|3|2|sep=<tr><td>|pc1=sep1=<td>}}
</table>

gives

  想搵3,請睇「1」、「5」、「3」同「2」。

Wikitable:

{| border=1
|-
|{{for|call=table row example|3|1|5|3|2|sep=&nbsp;
{{!}}-
{{!}}|pc1=sep1={{!!}}}}
|}

gives

  想搵3,請睇「1」、「5」、「3」同「2」。

Reserved name[編輯]

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」、「b」同「c」。

Related templates[編輯]

This template is another version of Template:foreach (talk, backlinks, edit). That version has stopped working due to some software change.

Comparison:

{{{v{{{2 }}}|{{{s }}}{{{{{c}}}|{{{pc1}}}|..|{{{pc4}}}|{{{pv}}}={{{2}}}}}}}}
{{{v{{{2|}}}|{{{s|}}}}}}{{{{{{{{v{{{2|}}}|c}}}|x0}}} |{{{pv}}}={{{2}}}|{{{pc1}}}|..|{{{pc4}}}}}

In the first case (for) the whole output is the default of a parameter named v{{{i }}} that is defined iff the ith parameter is not defined.

In the second case (foreach) the existence is checked twice, once for the separator and once for the main output; if the ith parameter is not defined a dummy template is called.

Both are based on Template:en (talk, backlinks, edit) . Differences are:

  • The Meta versions handle empty parameter values in the regular way, while the en version ignores them.
  • Template For allows "=" in parameter values
  • The difference in the case of conflicting parameter names, mentioned above.

See also[編輯]

有無可能取消斜體?[編輯]

中文字用斜體真係好唔美觀(範例)(又一盲目抄英維嘅事例),但研究咗 Template:For 好耐都搵唔到邊度改。如果識改不妨幫手改。--Kowlooner (傾偈) 2021年5月2號 (日) 12:15 (UTC)[回覆]