Difference between revisions of "Template:For nowiki/doc"

From blackwiki
Jump to navigation Jump to search
imported>BrandonXLF
(Expanded document to include the module)
imported>Pppery
(Undid revision 936808112 by BrandonXLF (talk) Again, the module is not intended to be used directly, so there is no reason to provide separate documentation for it)
Line 1: Line 1:
 
{{Documentation subpage}}
 
{{Documentation subpage}}
{{#ifeq:{{NAMESPACENUMBER}}|10|{{lua|Module:For nowiki}}|}}
+
{{lua|Module:For nowiki}}
  
This is the documentation for [[Template:For nowiki]] and [[Module:For nowiki]]. This module or template implements a [[foreach loop]]. It interprets a given wikitext (unlike {{tl|For loop}}, which calls a specified template) once for each item in the list.
+
This template implements a [[foreach loop]]. It interprets a given wikitext (unlike {{tl|For loop}}, which calls a specified template) once for each item in the list.
  
 
== Usage ==
 
== Usage ==
  {{tlp|For nowiki|''separator''|{{tag|nowiki|content=''wikitext''}}|''item1''|''item2''|...}}
+
  {{tlp|For nowiki|''separator''|{{tag|nowiki|content=''wikitext''}}|item1|item2|...}}
 
  {{tlp|For nowiki|''separator''|{{tag|nowiki|content=''wikitext''}}|count{{=}}''count''}}
 
  {{tlp|For nowiki|''separator''|{{tag|nowiki|content=''wikitext''}}|count{{=}}''count''}}
{{((}}#invoke:For nowiki|template|''separator''|{{tag|nowiki|content=''wikitext''}}|''force one loop''}}
 
 
;General parameters
 
 
* <code>''separator''</code> is inserted ''between'' the results of <code>''wikitext''</code> interpretation. Whitespace is preserved.
 
* <code>''separator''</code> is inserted ''between'' the results of <code>''wikitext''</code> interpretation. Whitespace is preserved.
 
* <code>''wikitext''</code> is interpreted once for each item in the list. It then may use {{code|<nowiki>{{{1}}}</nowiki>}} to get the item value, and {{code|<nowiki>{{{i}}}</nowiki>}} to get its position in the list (starting from 1), as well as any parameters that were passed to {{tl|for nowiki}}. It may also contain template calls. To use a parameter passed to the calling template, surround it with {{nowrap|<code></nowiki>...<no<!---->wiki></code>}} (the opening and closing tags are swapped) or pass the parameter directly to {{tl|for nowiki}} if its name doesn't conflict with any reserved parameters.
 
* <code>''wikitext''</code> is interpreted once for each item in the list. It then may use {{code|<nowiki>{{{1}}}</nowiki>}} to get the item value, and {{code|<nowiki>{{{i}}}</nowiki>}} to get its position in the list (starting from 1), as well as any parameters that were passed to {{tl|for nowiki}}. It may also contain template calls. To use a parameter passed to the calling template, surround it with {{nowrap|<code></nowiki>...<no<!---->wiki></code>}} (the opening and closing tags are swapped) or pass the parameter directly to {{tl|for nowiki}} if its name doesn't conflict with any reserved parameters.
  
;Use 1 specific
+
The second form of this template using a {{para|count}} parameter interprets the given wikitext count times, passing each integer between 1 and that count as both {{para|1}} and {{para|i}} each time.
* <code>''item1''</code>, <code>''item2''</code>, <code>''...''</code> are the items to iterate through, with {{code|<nowiki>{{{1}}}</nowiki>}} being replaced with the value and {{code|<nowiki>{{{i}}}</nowiki>}} with the name of the parameter/index.
 
 
 
;Use 2 specific
 
* <code>count=''count''</code> is the number of times to interpret the provided wikitext. The template will pass each integer between 1 and that count as both {{para|1}} and {{para|i}} each time.
 
 
 
;Use 3 specific
 
* <code>''force one loop''</code> forces the module to perform at least one loop, this is useful when you provide a default value for {{code|<nowiki>{{{1}}}</nowiki>}}.
 
 
 
* When using the module, numbered/unnamed parameters sent to the template (the page the module is used on) will be iterated through, with {{code|<nowiki>{{{1}}}</nowiki>}} being replaced with the value and {{code|<nowiki>{{{i}}}</nowiki>}} with the name of the parameter/index.
 
  
 
== Example ==
 
== Example ==

Revision as of 05:33, 21 January 2020

This template implements a foreach loop. It interprets a given wikitext (unlike {{For loop}}, which calls a specified template) once for each item in the list.

Usage

{{For nowiki|separator|<nowiki>wikitext</nowiki>|item1|item2|...}}
{{For nowiki|separator|<nowiki>wikitext</nowiki>|count=count}}
  • separator is inserted between the results of wikitext interpretation. Whitespace is preserved.
  • wikitext is interpreted once for each item in the list. It then may use {{{1}}} to get the item value, and {{{i}}} to get its position in the list (starting from 1), as well as any parameters that were passed to {{for nowiki}}. It may also contain template calls. To use a parameter passed to the calling template, surround it with </nowiki>...<nowiki> (the opening and closing tags are swapped) or pass the parameter directly to {{for nowiki}} if its name doesn't conflict with any reserved parameters.

The second form of this template using a |count= parameter interprets the given wikitext count times, passing each integer between 1 and that count as both |1= and |i= each time.

Example

Markup Renders as
{{For nowiki|
|<nowiki>* Item {{{i}}}: {{3x|{{{1}}} }}</nowiki> |dog|cat|bird}}
  • Item 1: dog dog dog
  • Item 2: cat cat cat
  • Item 3: bird bird bird

See also