Module:Iteration/doc: Difference between revisions
More actions
m format |
m format |
||
| Line 20: | Line 20: | ||
end | end | ||
return table.concat (out)|lang="text"}} | return table.concat (out)|lang="text"}} | ||
The functions contained therein are from very simple, just one parameter to pass, <br> | The functions contained therein are from very simple, just one parameter to pass, <br> | ||
to more complicated ones, where e.g. a pair of parameters needs kind of a flip-flop switch<br> | to more complicated ones, where e.g. a pair of parameters needs kind of a flip-flop switch<br> | ||
| Line 39: | Line 38: | ||
=== Other file lists === | === Other file lists === | ||
The <tt>function:svglang</tt> creates a list of just file_names and language_codes, for | |||
#<li value="6"> {{T0|Svg lang}} | #<li value="6"> {{T0|Svg lang}} | ||
# {{T0|Lang gallery}} | # {{T0|Lang gallery}} | ||
Much more is created by the <tt>function:ownbased</tt> for the template | |||
#<li value="8">{{T0|Own based}}<br> | #<li value="8">{{T0|Own based}}<br> | ||
which will handle in the ''majority of cases'' just one file, but can serve an unlimited number. | which will handle in the ''majority of cases'' just one file, but can serve an unlimited number.<br> | ||
This list can be controlled by the user to be displayed <tt>either</tt> horizontally or vertically.<br><br> | |||
Revision as of 21:40, 23 July 2020
This module contains the functions for different templates, solving their iteration problem
- The Wikipedia template coding does not support the repetitive processing of a parameter set,
- which leads often to a very primitive and long chain of parameter checks in the kind of
{{#if:{{{1|}}} | perform an action with parameter 1 }} {{#if:{{{2|}}} | perform an action with parameter 2 }} {{#if:{{{3|}}} | perform an action with parameter 3 }} {{#if:{{{4|}}} | perform an action with parameter 4 }} ••• ••• {{#if:{{{33|}}} perform an action with parameter 33 }}
with the disadvantage that such a construct will fail as soon as there comes a 34nd parm.
I always thought that with Lua and its for loops this iterations should be possible, somehow.
After long searching without any success and without an idea how to perform it, I asked at several forums
and got finally from User:Trappist the monk the helping hint to solve it with a control structure like
local out = {}
for i, v in ipairs (args) do
table.insert (out, frame:expandTemplate{ title = title, args = v })
end
return table.concat (out)
The functions contained therein are from very simple, just one parameter to pass,
to more complicated ones, where e.g. a pair of parameters needs kind of a flip-flop switch
when always a tuple of e.g. an item and its correlated text needs to be passed.
When there are tuples, triples etc., the table.insert occurs, when the last element is processed;
this performs problems when the last group is incomplete – it should be finished with empty values
to trigger the table.insert. The check with table.maxn seems not to work correctly ?
This problem is solved differently, for the function "attribs" with a primitive workaround.
File list templates
There are currently five templates creating file lists with the function:filelist
- Other versions a vertical list (without initial)
- Filelist a horizontal list (without initial)
- Derivative versions a vertical list
- Derived from a vertical list
- File a horizontal list
Other file lists
The function:svglang creates a list of just file_names and language_codes, for
Much more is created by the function:ownbased for the template
which will handle in the majority of cases just one file, but can serve an unlimited number.
This list can be controlled by the user to be displayed either horizontally or vertically.