Jump to content

Template talk:For loop

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
(Redirected from Template talk:For loop/doc)

Suppress separator (1=) when returned value is empty

[edit]
Resolved

The separator (|1=) should be suppressed if the returned value for a parameter is empty. It's already doing this when the input is empty (regardless whether |skipBlanks=y is set). Example:

produces:

The comma-space is being passed as the separator to this template by that one. It is being generated for the invalid "Foo" entry which returns nothing from the template that is called. The empty parameters (which, if numbered, would |3= and |4=) do not have this problem.  — SMcCandlish ¢ 😼  12:01, 23 December 2018 (UTC)[reply]

Pppery fixed it.  — SMcCandlish ¢ 😼  05:02, 22 February 2019 (UTC)[reply]

How to automate transclusion of numbered templates?

[edit]

I'm trying to remove the duplication on the page Portal:Doctor Who/Selected quotes, which transcludes ten subpages {{Portal:Doctor Who/Selected quotes/1}} .. {{Portal:Doctor Who/Selected quotes/10}}. The specialty of {{For loop}} is passing a changing parameter into a single particular template.

I've tried tricking {{For loop}} into transclusion of several different templates using {{1x}} and brackets {{((}} and {{))}} as follows:

{{for loop|1=<div style="clear: both"></div><br/><hr/><br/>|call=1x|prefix={{((}}Portal:Doctor Who/Selected quotes/|postfix={{))}}|start=1|stop=10}}

but this only outputs the wikitext of transclusions {{Portal:Doctor Who/Selected quotes/1}} .. {{Portal:Doctor Who/Selected quotes/10}}:

Output
{{Portal:Doctor Who/Selected quotes/1}}



{{Portal:Doctor Who/Selected quotes/2}}



{{Portal:Doctor Who/Selected quotes/3}}



{{Portal:Doctor Who/Selected quotes/4}}



{{Portal:Doctor Who/Selected quotes/5}}



{{Portal:Doctor Who/Selected quotes/6}}



{{Portal:Doctor Who/Selected quotes/7}}



{{Portal:Doctor Who/Selected quotes/8}}



{{Portal:Doctor Who/Selected quotes/9}}



{{Portal:Doctor Who/Selected quotes/10}}

is there any way to use {{for loop}} to achieve this? I've also tried using Template:Eval, but it is only for substing. —⁠andrybak (talk) 21:09, 24 May 2020 (UTC)[reply]

Instead of {{1x}}, use {{expand wikitext}}:
Output




























swpbT • go beyond • bad idea 15:08, 27 May 2020 (UTC)[reply]
FYI this can be done without {{for loop}}. For example, by using template {{Numbered subpages}}. See more at Wikipedia:WikiProject Portals § Templates. —⁠andrybak (talk) 17:18, 7 June 2020 (UTC)[reply]

 You are invited to join the discussion at Wikipedia:Village pump (technical) § For loops for a category. {{u|Sdkb}}talk 23:29, 3 December 2020 (UTC)[reply]

use the PV value twice in the for loop

[edit]

I am looking to use the process variable twice in the for loop. This example loop uses it once.

{{for loop|{{!}}|call = if
  |pv = 2
  |start=1|stop=6|by=1
  |postfix = >4
  |pc1n = 3 |pc1v = pv
  |pc2n = 4 |pc2v = 0
  |pc3n = 1 |pc3v = expr
}}

It creates this string

 0|0|0|0|pv|pv 

But I want to create the string

 0|0|0|0|5|6 

Jrkenti (talk) 00:56, 15 April 2022 (UTC)[reply]

This template isn't set up to do that by itself. One way to do this would be to create another template that performs the math, and call that template with a for loop:, e.g.:
New template "if_gt_4":
{{if|expr|{{{1}}}>4|{{{1}}}|0}}
For loop call:
{{for loop|{{!}}|call = if_gt_4 |start=1|stop=6|by=1}}
I've set this up using my sandbox: CT May 24, 2018
2018 January 30, 2016


nine|CT May 24, 2018

2018 January 30, 2016


nine|CT May 24, 2018

2018 January 30, 2016


nine|CT May 24, 2018

2018 January 30, 2016


nine|CT May 24, 2018

2018 January 30, 2016


nine|CT May 24, 2018

2018 January 30, 2016


nine

swpbT • go beyond • bad idea 15:15, 18 April 2022 (UTC)[reply]