Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Renders a card with an image, title, and details section. Used by the {{Card}} template, typically grouped inside {{CardGrid}} for multi-card layouts.

Parameters

Parameter Description Status
image Filename of the card's image; placeholder is shown if omitted. Required
title Card's title; also used as the link target if link is not provided. Optional
link Page the card links to; defaults to title if omitted Optional
details A short description. Optional

If the image filename contains "Icon", the card automatically applies the icon modifier (centered with padding).


local Card = {}

-- Thumbnail sizes requested from MediaWiki.
local IMAGE_SIZE = 200
local ICON_SIZE = 128

-- Fallback when no image is supplied by the caller.
local MISSING_IMAGE = 'Icon_ARC.png'

-- Convert raw template args into normalized values.
local function normalize(args)
    local title = args.title ~= '' and args.title or nil
    return {
        image   = args.image   ~= '' and args.image   or MISSING_IMAGE,
        title   = title,
        details = args.details ~= '' and args.details or nil,
        link    = args.link    ~= '' and args.link    or title or '',
    }
end

local function renderImage(parent, image, link)
    local isIcon = string.find(image, '^Icon')
    local size = isIcon and ICON_SIZE or IMAGE_SIZE

    local imageTag = parent:tag('div')
        :addClass('card__image')
    if isIcon then
        imageTag:addClass('card__image--icon')
    end
    imageTag:wikitext(string.format('[[File:%s|%dpx|link=%s]]', image, size, link))
end

local function renderTitle(parent, title, link)
    if not title then return end
    parent:tag('div')
        :addClass('card__title')
        :wikitext(string.format('[[%s|%s]]', link, title))
end

local function renderDetails(parent, details)
    if not details then return end
    parent:tag('div')
        :addClass('card__details')
        :wikitext(details)
end

local function build(args)
    local html = mw.html.create('div'):addClass('card')
    renderImage(html, args.image, args.link)
    
    local content = html:tag('div'):addClass('card__content')
    renderTitle(content, args.title, args.link)
    renderDetails(content, args.details)

    return html
end

function Card.main(frame)
    local args = normalize(frame:getParent().args)
    local html = build(args)
    
    local styles = frame:extensionTag{
        name = 'templatestyles',
        args = {src = 'Template:Card/styles.css'}
    }

    return styles .. tostring(html)
end

return Card