Weitere Optionen
local mArguments --initialize lazily local p = {}
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local function getArgNums(prefix, args)
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
--Implements Vorlage:Documentation
- Description
- A template link with a variable number of example parameters (0-20), which can be used to show example inputs.
- Utilises Template:T/piece.
- Syntax
- Vorlagenschleife entdeckt: Vorlage:T
- Sample code
{{t|welcome}}
gives...- Vorlagenschleife entdeckt: Vorlage:T
{{t|welcome|Item1|Item2|Item3|Item4|Item5|...}}
gives...- Vorlagenschleife entdeckt: Vorlage:T
- See also
- Template:T on WoWWiki is used to create a grid of navigation button.
Optimized background image resolution: 400x92px
Example
<syntaxhighlight lang="mediawiki"> Vorlagenschleife entdeckt: Vorlage:Navpills </syntaxhighlight>
will give:
Vorlagenschleife entdeckt: Vorlage:Navpills from the frame function p.navpills( frame ) mArguments = require( 'Module:Arguments' ) return p._navpills( mArguments.getArgs( frame ) ) end
function p._navpills( args ) if not args then return 'Missing arguments' end
local html = mw.html.create( 'div' ):addClass( 'template-navpills' ):attr( 'role', 'navigation' )
for i, _ in ipairs( getArgNums( 'page', args ) ) do if not args[ 'page' .. i ] then return end local num = tostring( i ) local navpill = mw.html.create('div'):addClass('template-navpill')
if args[ 'image' .. i ] then navpill:tag('div'):addClass('template-navpill-background') :wikitext( string.format( 'Datei:%s', args[ 'image' .. num ] ) ) end
navpill:wikitext( string.format( '%s', args[ 'page' .. num ], args[ 'text' .. num ] or args[ 'page' .. num ] ) ) html:node(navpill) end
return mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Module:Navpills/styles.css' } } .. tostring( html ) end
return p