Difference between revisions of "Module:Infobox"
Jump to navigation
Jump to search
m (Raise max field length to 13.) |
m |
||
Line 47: | Line 47: | ||
push('! Original run') | push('! Original run') | ||
-- Add timespan | -- Add timespan | ||
− | pushf('| %s - %s', pargs['start'] or 'unknown', pargs['end'] or 'present') | + | if pargs['start'] == pargs['end'] then |
+ | pushf('| %s', pargs['start']) | ||
+ | else | ||
+ | pushf('| %s - %s', pargs['start'] or 'unknown', pargs['end'] or 'present') | ||
+ | end | ||
end | end | ||
Latest revision as of 18:53, 7 February 2021
A meta-template script for creating new infobox templates. All infoboxes on this wiki are generated via a Lua script to make them easier to develop.
Usage
Create a new page at Template:Infobox_xxx
where xxx
is the type of your new template. #invoke
this script and pass the name of your rows as parameters like follows:
{{#invoke:Infobox|infobox | label1 = Name as it will appear in the infobox | data1 = Template parameter name assigned to this label | section2 = Name of a new section | label3 = Continue adding new labels... | data3 = ...adding one for each row }}
The template generated by this script can be called like any normal template. In addition to user-defined rows, every infobox also has some pre-defined parameters:
- The first, unnamed parameter is the name of the page as it appears on Wikipedia. The default is
[[Wikipedia:{{PAGENAME}}|Wikipedia]]
. title
is an optional parameter that defines the name of the infobox. Otherwise, it will default to{{PAGENAME}}
.image
andimagewidth
define the infobox's file and the width in pixels. If left unspecified, the image will fill the width of the box.start
andend
is the original run of the show/comic/etc. If either is left undefined they will default to unknown and present.
See the documentation of the individual infobox templates for examples of how these are used.
local p = {} local wikitext = {} function push(text) wikitext[#wikitext + 1] = text end function pushf(s, ...) wikitext[#wikitext + 1] = s:format(...) end function p.infobox(frame) local args = frame.args local pargs = frame:getParent().args local pagename = frame:preprocess('{{PAGENAME}}') -- Add header and title push('{| class="infobox"') push('|-') pushf('! class="infobox-header" colspan="2" | %s', pargs.title or pagename) -- Add optional image if pargs.image then push('|-') pushf('| class="infobox-image" colspan="2" | [[File:%s|%spx]]', pargs.image, pargs.imagewidth or '324') end -- Iterate through template rows for i=1,13 do if pargs[args['data' .. i]] then -- Add row header push('|-') pushf('! %s', args['label' .. i]) -- Add row data pushf('| %s', pargs[args['data' .. i]]) elseif args['section' .. i] then -- Add section header push('|-') pushf('! class="infobox-section" colspan="2" | %s', args['section' .. i]) end end -- Add hardcoded time row at end if pargs['start'] or pargs['end'] then -- Add time header push('|-') push('! Original run') -- Add timespan if pargs['start'] == pargs['end'] then pushf('| %s', pargs['start']) else pushf('| %s - %s', pargs['start'] or 'unknown', pargs['end'] or 'present') end end -- Add Wikipedia footer push('|-') pushf('! class="infobox-footer" colspan="2" | [[Wikipedia:%s|Wikipedia]]', pargs[1] or pagename) push('|}') return table.concat(wikitext, '\n') end return p