Module:Infobox
From Chalo Chatu, Zambia online encyclopedia
Jump to navigationJump to search
Lua error in Module:High-use at line 164: attempt to call field 'main' (a nil value). Script error: The function "ombox" does not exist.
This module implements the {{Infobox}} template. Please see the template page for usage instructions.
Tracking/maintenance categories
- Category:Articles which use infobox templates with no data rows
- Category:Pages which use embedded infobox templates with the title parameter
-- Simplified version of Module:Infobox for Chalo Chatu
local p = {}
local args = {}
local root = nil
-- Get arguments and strip empty
local function getArgs(frame)
local origArgs = frame:getParent().args
for k, v in pairs(origArgs) do
if v and mw.text.trim(v) ~= '' then
args[k] = v
end
end
end
-- Build the infobox table
local function buildInfobox()
root = mw.html.create('table')
root:addClass('infobox')
:cssText(args.bodystyle or '')
:addClass(args.bodyclass or '')
-- Caption
if args.title then
root:tag('caption')
:addClass('infobox-title')
:cssText(args.titlestyle or '')
:wikitext(args.title)
end
-- Above
if args.above then
root:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('infobox-above')
:cssText(args.abovestyle or '')
:wikitext(args.above)
end
-- Image
if args.image then
local img = root:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('infobox-image')
:cssText(args.imagestyle or '')
:wikitext(args.image)
if args.caption then
img:tag('div')
:addClass('infobox-caption')
:cssText(args.captionstyle or '')
:wikitext(args.caption)
end
end
-- Rows
for i = 1, 50 do
local label = args['label' .. i]
local data = args['data' .. i]
if data then
local row = root:tag('tr')
if label then
row:tag('th')
:addClass('infobox-label')
:cssText(args.labelstyle or '')
:wikitext(label)
row:tag('td')
:addClass('infobox-data')
:cssText(args.datastyle or '')
:wikitext(data)
else
row:tag('td')
:attr('colspan', '2')
:addClass('infobox-data')
:cssText(args.datastyle or '')
:wikitext(data)
end
end
end
-- Below
if args.below then
root:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('infobox-below')
:cssText(args.belowstyle or '')
:wikitext(args.below)
end
return tostring(root)
end
function p.infobox(frame)
getArgs(frame)
return buildInfobox()
end
return p