Welcome to the DFO World Wiki. With many major updates since the release of DFO, many items are missing. Visit Item Database Project to learn more.
Please remember to click "show preview" before saving the page.
Thanks for the updated logo snafuPop!

Difference between revisions of "Template:Horizontal scale loop/doc"

From DFO World Wiki
Jump to: navigation, search
m (Dfoplayer moved page Template:For loop/doc to Template:For/doc without leaving a redirect: migrate to a non lua)
m (remove calc increment)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
Uses Extension:Arrays to perform the for loop.
  
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE. -->
+
== Description ==
[[Template:For loop]] implements a [[for loop]] or a [[foreach loop]].
+
The template calls {{tl|Horizontal scale}}
 
 
This template calls a user-specified template (the "called template") once for each value in either 1) an iterated sequence or 2) an explicit list. A specified parameter of the called template is passed each value in the sequence or list (with optional pre- and postfixes attached). The first unnamed parameter of this template (the "separator") is output between calls to the called template. In addition to the one variable-valued parameter, other "static" parameters of the called template can be passed, with the same value in each iteration.
 
  
 
== Usage ==
 
== Usage ==
{| class="wikitable"
 
! Parameter !! Value !! Notes
 
|-
 
| '''1 (unnamed)''' || separator to output between calls (whitespace is preserved) || '''MANDATORY''' (may be blank)
 
|-
 
| '''call''' || template to call || '''MANDATORY'''
 
|-
 
| '''pv''' || name of the variable parameter to pass to the called template || '''MANDATORY''' unless it is the first unnamed parameter of the called template (use integers for other unnamed parameters)
 
|-
 
| '''pc[N]n''' || name (or number) of the Nth static parameter to pass to the called template ||
 
|-
 
| '''pc[N]v''' || value of the Nth static parameter to pass to the called template ||
 
|-
 
| '''prefix''' || static prefix prepended to each of the variable values ||
 
|-
 
| '''prefix''' || static postfix appended to each of the variable values ||
 
|-
 
| '''substall''' || false to not substitute the called template when {{tl|for loop}} is substituted (defaults to true) ||
 
|- style="border-top: 3px solid grey;"
 
| '''start''' || first value to pass to variable parameter (defaults to 1) || rowspan=3 | '''Option 1: iterator'''
 
|-
 
| '''stop''' || maximum value for variable parameter
 
|-
 
| '''by''' || iteration step size between values passed to variable parameter (defaults to 1)
 
|- style="border-top: 3px solid grey;"
 
| '''(unnamed)''' || | explicit list of variable values, given as separate parameters (whitespace is stripped) || rowspan=2 | '''Option 2: explicit values'''
 
|-
 
| '''skipBlanks''' || true to skip empty parameter values (defaults to false)
 
|}
 
  
Note that ''either'' iterator parameters (option 1) ''or'' an explicit list of values (option 2) may be used, but not both.
 
<!--
 
 
<pre>
 
<pre>
{{for loop|<!-- separator, whitespace is preserved --><!--|
+
{{Horizontal scale loop
    call    = template to call
+
   |times=how many you want to loop to go using a comma separated list
   | pc1n    = name  of the 1st static parameter passed to the called template
+
   |from=starting number
  | pc1v    = value of the 1st static parameter passed to the called template
+
   |to=ending number
   | pc2n    = name  of the 2nd static parameter passed to the called template
+
   |increment=what the increment is.
   | pc2v    = value of the 2nd static parameter passed to the called template
 
  | pc3n    = name  of the 3rd static parameter passed to the called template
 
  | pc3v    = value of the 3rd static parameter passed to the called template
 
<!-- More fixed parameters passed to the called template can be inserted as needed -->
 
<!--
 
   | pv      = name of the parameter passed to the called template, to which is
 
                assigned the variable values (with optional pre- and postfixes attached).
 
  | prefix  = static prefix prepended to each of the variable values
 
  | postfix = static postfix appended to each of the variable values
 
  | skipBlanks = whether to include skip empty parameter values
 
<!-- EITHER: -->
 
<!--
 
  | start = first variable value to pass (defaults to 1)
 
  | stop = maximum value for variable value
 
  | by = iteration step size between values (defaults to 1)
 
<!-- OR: -->
 
<!--
 
  | explicit list of variable values with separator "|" (whitespace is stripped)
 
    (unless skipBlanks is specified and true, empty parameter values work in the regular way, they are ''not'' ignored like undefined ones)
 
 
}}
 
}}
 
</pre>
 
</pre>
-->
 
 
The separator is the first unnamed parameter, allowing it to start and/or end with [[Help:newlines and spaces|newlines and spaces]]. The separator is output ''between'' calls to the template named in <code>|call=</code>. It is not output after the last call to that template. The separator parameter is prior to the value list. If a value in the list contains an equals sign, use {{tlx|{{=}}}} (see [[Help:Template#Usage hints and workarounds|Help:Template]]).  If you do not use {{tlx|{{=}}}}, the list must use named parameters, at least from that point. If you use named parameters, note that the first value is parameter 2 (e.g. <code>|2=Your1stValue</code>), because parameter 1 is the separator. If the separator contains an equals sign, {{tlx|{{=}}}} should also be used. Alternately, the separator can similarly be prefixed with "1=", but in that case it cannot contain newlines and spaces at the start and end. Also, if you use named parameters, you must not skip any numbers. The loop will terminate after the first absent numbered parameter. (Note that parameters can be blank but not absent; blank parameters are read as normal.)
 
  
 
==Examples==
 
==Examples==
 
{| class="wikitable", border=1
 
{| class="wikitable", border=1
 
!Code
 
!Code
!Explanation
 
 
!Result
 
!Result
 
|-
 
|-
 
|
 
|
<pre>{{for loop|&|call = spanbox
+
<pre>{{Horizontal scale loop
  |pc1n = 1
+
|times=1
  |pc1v = A
+
|from=1
  |pc2n = background
+
|to=100
  |pc2v = yellow
+
|increment=5
  |pv = font size
 
  |postfix = px
 
  |start=10|stop=46|by=8
 
 
}}</pre>
 
}}</pre>
| Outputting "&" between calls, call the template "spanbox" with values:
+
|{{Horizontal scale loop
*1 (first unnamed parameter) = "A"
+
|times=1
*background = "yellow"
+
|from=1
*font size = "[N]px", where N takes values starting with 10 and increasing by 8 while remaining less than 46
+
|to=100
|{{for loop|&|call = spanbox
+
|increment=5
  |pc1n = 1
 
  |pc1v = A
 
  |pc2n = background
 
  |pc2v = yellow
 
  |pv = font size
 
  |postfix = px
 
  |start=10|stop=46|by=8
 
 
}}
 
}}
 
|-
 
|-
|<pre>1{for loop|, |call=1x
+
|
|prefix=1
+
<pre>{{Horizontal scale loop
|00|01|02|03|04|05|06|07|08|09
+
|times=1,2,3,4,5
|10|11|12|13|14|15|16|17|18|19
+
|from=1
|20|21|22|23|24|25|26|27|28|29
+
|to=100
|30|31|32|33|34|35|36|37|38|39
+
|increment=5
|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
 
 
}}</pre>
 
}}</pre>
| Call the template "1x" with values "1[NN]", where NN = "00" through "99" (given explicitly), separating the outputs with the string ", "
+
|{{Horizontal scale loop
|{{for loop|, |call=1x
+
|times=1,2,3,4,5
|prefix=1
+
|from=1
|00|01|02|03|04|05|06|07|08|09
+
|to=100
|10|11|12|13|14|15|16|17|18|19
+
|increment=5
|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
 
 
}}
 
}}
 
|}
 
|}
  
===Other examples===
+
<includeonly>[[Category:Repetition templates]]</includeonly>
 
 
<nowiki>{{for loop|-|a|3||c|g|call=3x}}</nowiki> using {{tiw|3x}} gives
 
 
 
{{for loop|-|a|3||c|g|call=3x}}
 
 
 
<nowiki>{{for loop|</nowiki>
 
 
 
<nowiki>|a|3||c|g|call=3x}}</nowiki> gives
 
 
 
{{for loop|
 
 
 
|a|3||c|g|call=3x}}
 
 
 
<pre>
 
{|class="wikitable sortable"
 
|-
 
!Test
 
|-
 
| {{for loop|
 
{{!}}-
 
{{!}} |a|b|c|d|e|call=3x}}
 
|}
 
</pre>
 
 
 
gives:
 
 
 
{|class="wikitable sortable"
 
|-
 
!Test
 
|-
 
| {{for loop|
 
{{!}}-
 
{{!}} |a|b|c|d|e|call=3x}}
 
|}
 
 
 
<pre>
 
{{for loop| |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
 
|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119
 
|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139
 
|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|call=1x}}
 
</pre>
 
gives:
 
 
 
{{for loop| |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
 
|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119
 
|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139
 
|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|call=1x}}
 
 
 
<pre>
 
begin->{{for loop|{{=}} |01|02|03|04|05|06|07|08|09|10
 
|11{{=}}{{=}}{{=}}|12|13|14|15|16|17|18|19|call=1x}}<-end
 
</pre>
 
gives:
 
 
 
begin->{{for loop|{{=}} |01|02|03|04|05|06|07|08|09|10
 
|11{{=}}{{=}}{{=}}|12|13|14|15|16|17|18|19|call=1x}}<-end
 
 
 
== Legacy code ==
 
 
 
This template is currently in its third incarnation. It now uses the [[WP:Lua|Lua]] code at [[Module:ForLoop]]. It was ported to Lua from [[mw:Help:Extension:ParserFunctions|ParserFunctions]]. There was also a previous version with a named "sep" parameter to specify the separator value. The template was originally based on [[:m:Template:For]]. The template name was changed because there was already a [[Template:For]] on Wikipedia.
 
 
 
The old versions were limited to 150 variable values and four fixed parameters. There are no such limits in the current version. Also, in the first version the "sep" parameter didn't allow whitespace in the separator value. This was fixed with the second version and was retained in the current version.
 
 
 
== Substitution ==
 
 
 
The current Lua-based template supports [[WP:SUBST|substitution]]. If {{para|substall|no}} is not specified, then substituting the template will substitute everything, including the call to the template passed in {{para|call}}. If it is specified, then the template substitutes into a sequence of calls to the template specified.
 
 
 
Example: {{tlsx|for loop|sep |01|02|03|04|05|06|07|call{{=}}1x}} -> <code><nowiki>01sep 02sep 03sep 04sep 05sep 06sep 07</nowiki></code>, {{tlsx|for loop|sep |01|02|03|04|05|06|07|call={{1x}}|substall{{=}}no}} -> <code><nowiki>{{1x|01}}sep {{1x|02}}sep {{1x|03}}sep {{1x|04}}sep {{1x|05}}sep {{1x|06}}sep {{1x|07}}</nowiki></code>
 
 
 
For full substitution [[Special:ExpandTemplates]] can also be used.
 
 
 
 
 
==See also==
 
*[[mw:Template:Fe]]
 
*{{tim|foreach}}
 
*{{tim|tblb}}
 
*{{tiw|for nowiki}}
 
*{{tiw|item}}
 
*{{tiw|loop}}
 
*{{tiw|repeat}}
 
*{{tiw|simple recursion}}
 
*[[Help:Parameter default]]
 
*[[Help:Array]]
 
*[[mw:Extension:LoopFunctions]]
 
 
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
 
<!-- CATEGORIES HERE, THANKS -->
 
[[Category:Wikipedia formatting and function templates]]
 
}}</includeonly>
 

Latest revision as of 11:30, 15 August 2018

Uses Extension:Arrays to perform the for loop.

Description

The template calls {{Horizontal scale}}

Usage

{{Horizontal scale loop
  |times=how many you want to loop to go using a comma separated list
  |from=starting number
  |to=ending number
  |increment=what the increment is.
}}

Examples

Code Result
{{Horizontal scale loop
|times=1
|from=1
|to=100
|increment=5
}}
|
6
{{Horizontal scale loop
|times=1,2,3,4,5
|from=1
|to=100
|increment=5
}}
|
6
|
11
|
16
|
21
|
26