Jump to content
Wikipedia The Free Encyclopedia

Template talk:For loop

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
icon This template was considered for deletion on 2006 December 20. The result of the discussion was "to keep".

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
" Your species has the most amazing capacity for self-deception, matched only by its ingenuity when trying to destroy itself. "



" On my travels to Cathay, Ian, I have come to believe many things I'd previously doubted. For instance, when I was a boy in Venice, they told me that in Cathay there was a stone that burned. I did not believe, but there is such a stone: I have seen it. And if stone burns, why not a caravan that flies? Birds fly; I have even seen fish that fly. You are asking me to believe that your caravan can defy the passage of the sun? Move not merely from one place to another, but from today into tomorrow, today to yesterday? No Ian, that I cannot believe. "



" Emotions! Love, pride, hate, fear! Have you no emotions, sir? "
First Doctor, talking to a Cyberman, The Tenth Planet


" I love a Happy Medium "



" The Time Lords are an immensely civilised race. We can control our own environment - we can live forever, barring accidents, and we have the secret of space-time travel. "



"
"Jo, it's all quite simple - I am he and he is me."
"And we are all together, goo-goo-goo-joob?"
"



" Homo sapiens. What an inventive, invincible species. It's only a few million years since they crawled up out of the mud and learned to walk. Puny, defenceless bipeds. They've survived flood, famine and plague. They've survived cosmic wars and holocausts. And now, here they are, out among the stars, waiting to begin a new life. Ready to outsit eternity. They're indomitable. "



" Look at me. No plans, no backup, no weapons worth a damn. Oh, and something else I don't have: anything to lose. So, if you're sitting up there with your silly little spaceships and your silly little guns and you've any plans on taking the Pandorica tonight; just remember who's standing in your way. Remember every black day I ever stopped you and then, and then, do the smart thing. Let somebody else try first. "



" There's something that doesn't make sense. Let's go and poke it with a stick. "



" Let me tell you something about the human race. You put a mysterious blue box slap-bang in the middle of town, what do they do? Walk past it. Now stop your nagging. Let's go and explore. "



" 'Cause that's how I see the universe. Every waking second, I can see what is, what was, what could be, what must not. That's the burden of a Time Lord, Donna. And I'm the only one left. "
swpb Tgo beyondbad 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

swpb Tgo beyondbad idea 15:15, 18 April 2022 (UTC) [reply ]

AltStyle によって変換されたページ (->オリジナル) /