From The Big Cartoon Wiki
Jump to navigation Jump to search

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.


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:

| 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:

  1. The first, unnamed parameter is the name of the page as it appears on Wikipedia. The default is [[Wikipedia:{{PAGENAME}}|Wikipedia]].
  2. title is an optional parameter that defines the name of the infobox. Otherwise, it will default to {{PAGENAME}}.
  3. image and imagewidth define the infobox's file and the width in pixels. If left unspecified, the image will fill the width of the box.
  4. start and end 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

function pushf(s, ...)
	wikitext[#wikitext + 1] = s:format(...)

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"')
	pushf('! class="infobox-header" colspan="2" | %s', pargs.title or pagename)
	-- Add optional image
	if pargs.image then
		pushf('| class="infobox-image" colspan="2" | [[File:%s|%spx]]', pargs.image, pargs.imagewidth or '324')
	-- Iterate through template rows
	for i=1,13 do
		if pargs[args['data' .. i]] then
			-- Add row header
			pushf('! %s', args['label' .. i])
			-- Add row data
			pushf('| %s', pargs[args['data' .. i]])
		elseif args['section' .. i] then
			-- Add section header
			pushf('! class="infobox-section" colspan="2" | %s', args['section' .. i])
	-- Add hardcoded time row at end
	if pargs['start'] or pargs['end'] then
		-- Add time header
		push('! Original run')
		-- Add timespan
		if pargs['start'] == pargs['end'] then
			pushf('| %s', pargs['start'])
			pushf('| %s - %s', pargs['start'] or 'unknown', pargs['end'] or 'present')
	-- Add Wikipedia footer
	pushf('! class="infobox-footer" colspan="2" | [[Wikipedia:%s|Wikipedia]]', pargs[1] or pagename)
	return table.concat(wikitext, '\n')

return p