Changes

Jump to navigation Jump to search
Created page with "<includeonly>{{Module rating|release}}{{Module rating|protected}}{{Heavily used module|very|edit=sandbox}}</includeonly> This module contains the functions for different templ..."
<includeonly>{{Module rating|release}}{{Module rating|protected}}{{Heavily used module|very|edit=sandbox}}</includeonly>
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 {{#tag:syntaxhighlight|<nowiki>
{{#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 }}</nowiki>|lang="text"}}
with the disadvantage that such a construct will fail as soon as there comes a 34{{exp|nd}} parm.

I always thought that with Lua and its <tt>for</tt> loops this iterations should be possible, somehow.<br>
After long searching without any success and without an idea how to perform it, I asked at several forums<br>
and got finally from {{Ut|Trappist the monk|+|en}} the helping hint to solve it with a control structure like{{#tag:syntaxhighlight|
local out = {}
for i, v in ipairs (args) do
table.insert (out, frame:expandTemplate{ title = title, args = v })
end
return table.concat (out)|lang="text"}}
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>
when always a tuple of e.g. an item and its correlated text needs to be passed. <br>
<br>
When there are tuples, triples etc., the <tt>table.insert</tt> occurs, when the last element is processed;<br>
this performs problems when the last group is incomplete – it should be finished with empty values <br>
to trigger the <tt>table.insert</tt>. The check with <tt>table.maxn</tt> seems not to work correctly ?<br>
''This'' problem is solved differently, for the function "attribs" with a primitive workaround.


=== File list templates ===
A very simple iteration, useable for everything, is performed by <code>function:iterate</code>.<br>
The three "Ifim " templates avoid to display the file itself as an 'other version'. <br>
There are currently five templates creating file lists with the <tt>function:filelist</tt>
# {{T0|Other versions}} a vertical list (without initial)
# {{T0|Filelist}} a horizontal list (without initial)
# {{T0|Derivative versions}} a vertical list
# {{T0|Derived from}} a vertical list
# {{T0|File}} a horizontal list
All these templates are {{C|Autoreferencing templates|autoreferencing}}, and the support also the "gallery" option.

=== 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}}
# {{T0|Lang gallery}}<!-- <br>and ''using'' the <code>file</code> parameter: -->
# {{T0|Multilingual SVG diagrams}}
Much more is created by the <tt>function:ownbased</tt> for the template
#<li value="9">{{T0|Own based}}<br>
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>
#<li value="10">{{T0|Attribs}}<br>
The template works, whether there is a user assigned for a file, or one filename follows another.

#<li value="11">{{T0|Emoji|Emotab}}<br>
The template displays a line of SVG emojis; Unicode characters/emojis can be displayed with the function {{T0|Emoji|Emodis}}.

=== Other iterations ===
* {{T\|Userlist|08}}: {{T0|Userlist}} with many formatting parameters
* {{T\|Colorbox|08}}: {{T0|ColorString}} and other color box templates
* {{T\|Legends |08}}: {{T0|Legtab}} combines single {{T0|Legend}}s
* {{T\|Tleparms|08}}: the metatemplate {{T0|Tle}} displays the parameter usage of a template
* {{T\|Navigate|08}}: {{T0|Navcat}} navigates through color categories
* {{T\|Emodis {{0}}|08}}: {{T0|Emoji}} displays (one or many) Unicode characters
:The function "{{T\|emodis|08}}" <u>dis</u>plays Unicode characters / <u>emo</u>jis; it can care for newlines, while
:The function "{{T\|emotab|08}}" displays a <u>tab</u>le of files / <u>emo</u>jis.
<br>
The function "'''incrhx'''" increments a hexadecimal number (parm 1) by a decimal number (parm 2).<br>
Valid numbers are assumed, no checking occurs !<br>
When parameter 2 is preceded by a minus, the first number is ''de''cremented by the second one

Navigation menu