Module:SimpleInfobox

From Chalo Chatu, Zambia online encyclopedia
Revision as of 01:11, 23 July 2025 by Chalochatu (talk | contribs) (Created page with "local p = {} function p.infobox(frame) local args = frame:getParent().args local root = mw.html.create('table') :addClass('infobox') :css('border','1px solid #aaa') :css('border-collapse','collapse') :css('background','#f8f8f8') :css('font-size','90%') :css('line-height','1.4') :css('width','23em') :css('margin','0.5em') -- Title if args.title and args.title:match('%S') then root:ta...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:SimpleInfobox/doc

local p = {}

function p.infobox(frame)
    local args = frame:getParent().args
    local root = mw.html.create('table')
        :addClass('infobox')
        :css('border','1px solid #aaa')
        :css('border-collapse','collapse')
        :css('background','#f8f8f8')
        :css('font-size','90%')
        :css('line-height','1.4')
        :css('width','23em')
        :css('margin','0.5em')

    -- Title
    if args.title and args.title:match('%S') then
        root:tag('caption')
            :css('font-size','110%')
            :css('font-weight','bold')
            :css('padding','.25em')
            :wikitext(args.title)
    end

    -- Image
    if args.image and args.image:match('%S') then
        root:tag('tr')
            :tag('td')
            :attr('colspan','2')
            :css('text-align','center')
            :css('padding','.25em')
            :wikitext('[[File:' .. args.image .. '|' .. (args.image_size or '200px') .. ']]')
    end

    -- Fields
    for i=1,30 do
        local label = args['label'..i]
        local data  = args['data'..i]
        if (label and label:match('%S')) or (data and data:match('%S')) then
            local tr = root:tag('tr')
            tr:tag('th')
                :css('background','#eaeaea')
                :css('text-align','left')
                :css('padding','.2em .5em')
                :wikitext(label or '')
            tr:tag('td')
                :css('padding','.2em .5em')
                :wikitext(data or '')
        end
    end

    return tostring(root)
end

-- alias
p.infoboxTemplate = p.infobox

return p