Template:Foreach/doc
{{#if: |
{{#if:x||
}} |{{#ifeq: doc | doc
|
{{
#ifeq: show | show
| {{
{{#switch:
{{#if:
|
| {{#if:
|
{{#ifeq:|
| talk
|
}}
|
{{#ifeq:template|template talk
| talk
| template
}}
}}
}}
| main | = ambox | talk = tmbox | user = ombox | project = ombox | file | image = imbox | mediawiki = ombox | template = ombox | help = ombox | category = cmbox | book = ombox | extension = ombox | other | #default = ombox
}} | type = notice | image = Error creating thumbnail: Unable to save thumbnail to destination | imageright = | class = | style = | textstyle = | text = This is a documentation subpage for Template:Foreach (see that page for the {{#if:
|{{{text1}}}
|{{#ifeq:Template | User
|template template
|{{#if:Template
|template
|article}}
}}
}} itself).
It contains usage information, categories, interlanguage links and other content that is not part of the original {{#if:
|{{{text2}}}
|{{#if:
|{{{text1}}}
|{{#ifeq:Template | User
|template template page
|{{#if:Template
|template page
|article}}
}}
}}
}}. | small = | smallimage = | smallimageright = | smalltext = | subst = | date = | name = }}
}}{{
#if:
|
| {{#ifeq:Template|Template|}}
}}
| }} }}
Purpose
To repeatedly use a template for each argument in a pipe delimited list. The template handles up to 30 list items.
Example
- Create comma delimited links to each hook in a list
{{foreach|Link|delim=, |Item A|Item B}} → {{#if:Item A|Item A}}{{#if:Item B|, Item B}}{{#if:|, [[{{{4}}}]]}}{{#if:|, [[{{{5}}}]]}}{{#if:|, [[{{{6}}}]]}}{{#if:|, [[{{{7}}}]]}}{{#if:|, [[{{{8}}}]]}}{{#if:|, [[{{{9}}}]]}}{{#if:|, [[{{{10}}}]]}}{{#if:|, [[{{{11}}}]]}}{{#if:|, [[{{{12}}}]]}}{{#if:|, [[{{{13}}}]]}}{{#if:|, [[{{{14}}}]]}}{{#if:|, [[{{{15}}}]]}}{{#if:|, [[{{{16}}}]]}}{{#if:|, [[{{{17}}}]]}}{{#if:|, [[{{{18}}}]]}}{{#if:|, [[{{{19}}}]]}}{{#if:|, [[{{{20}}}]]}}{{#if:|, [[{{{21}}}]]}}{{#if:|, [[{{{22}}}]]}}{{#if:|, [[{{{23}}}]]}}{{#if:|, [[{{{24}}}]]}}{{#if:|, [[{{{25}}}]]}}{{#if:|, [[{{{26}}}]]}}{{#if:|, [[{{{27}}}]]}}{{#if:|, [[{{{28}}}]]}}{{#if:|, [[{{{29}}}]]}}{{#if:|, [[{{{30}}}]]}}{{#if:|, [[{{{31}}}]]}}{{#if:|, [[{{{32}}}]]}}{{#if:|, [[{{{33}}}]]}}{{#if:|, [[{{{34}}}]]}}{{#if:|, [[{{{35}}}]]}}{{#if:|, [[{{{36}}}]]}}{{#if:|, [[{{{37}}}]]}}{{#if:|, [[{{{38}}}]]}}{{#if:|, [[{{{39}}}]]}}{{#if:|, [[{{{40}}}]]}}{{#if:|, [[{{{41}}}]]}}{{#if:|, [[{{{42}}}]]}}{{#if:|, [[{{{43}}}]]}}{{#if:|, [[{{{44}}}]]}}{{#if:|, [[{{{45}}}]]}}{{#if:|, [[{{{46}}}]]}}{{#if:|, [[{{{47}}}]]}}{{#if:|, [[{{{48}}}]]}}{{#if:|, [[{{{49}}}]]}}{{#if:|, [[{{{50}}}]]}}{{#if:|, [[{{{51}}}]]}}
Usage
{{Foreach[|delim=delim]|templatename|item1[|item2]...}}
- templatename - the name of a template that takes at least one parameter. Only the first parameter will be used, so the remaining parameters must be optional.
- item1 - the first item to pass to the template, resulting in {{templatename|item1}}
- item2,... - (optional) the second and following items to pass to the template, resulting in {{templatename|item2}}, etc.
- delim - (optional) a delimiter that should be inserted between the list items after the template templatename has been applied to each