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

Module:InfoboxCat

From Silly Cats Wiki
Revision as of 22:22, 6 May 2025 by Phantom (talk | contribs) (Created page with "local p = {} function p.infobox(frame) local args = frame:getParent().args local infobox = mw.html.create('table') :addClass('infobox') :css('width', '300px') :css('border', '1px solid #aaa') -- Title if args.title then infobox:tag('tr') :tag('th') :attr('colspan', '2') :css('text-align', 'center') :wikitext(args.title) end -- Image if args.image then infobox:tag('tr') :tag('td') :attr('colspan', '2') :css('text-align', 'center')...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.infobox(frame)
	local args = frame:getParent().args
	local infobox = mw.html.create('table')
		:addClass('infobox')
		:css('width', '300px')
		:css('border', '1px solid #aaa')

	-- Title
	if args.title then
		infobox:tag('tr')
			:tag('th')
			:attr('colspan', '2')
			:css('text-align', 'center')
			:wikitext(args.title)
	end

	-- Image
	if args.image then
		infobox:tag('tr')
			:tag('td')
			:attr('colspan', '2')
			:css('text-align', 'center')
			:wikitext('[[File:' .. args.image .. '|250px]]')
	end

	-- Fields
	local fields = {
		{"Alias", "alias"},
		{"Sex", "gender"},
		{"Nation from", "nationality"},
		{"Breed", "breed"},
		{"Coat", "fur_color"},
		{"Born", "born"},
		{"Abandoned", "abandoned"},
		{"Rescued", "rescued"},
		{"Adopted", "adopted"},
		{"Died", "died"},
		{"Cause of death", "cause_of_death"},
		{"Resting place", "resting_place"},
		{"Occupation", "occupation"},
		{"Mate(s)", "mates"},
		{"Weight", "weight"},
		{"Height", "height"},
		{"Owner", "owner"},
		{"Known for", "known_for"},
		{"Sound", "sound"},
		{"Social Media", "social_media"},
	}

	for _, field in ipairs(fields) do
		local label, key = field[1], field[2]
		local value = args[key]
		if value and value ~= '' then
			local row = infobox:tag('tr')
			row:tag('th'):wikitext(label)
			row:tag('td'):wikitext(value)
		end
	end

	return tostring(infobox)
end

return p