Module:Infobox
![]() | This Lua module is used on approximately 3,310,000 pages, or roughly 2902594% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
{{#ifeq:Infobox|doc|{{#if:|Template:Pp}}|{{#switch:
{{#if: | | {{#ifeq:Module|Module | module | other }} }}
| module = Template:Ombox{{#if:|| {{#ifeq: Module:Infobox | Sandbox
| | {{#switch: Infobox | doc | sandbox = | {{#ifeq: | true | | {{#switch: protected | pre-alpha | prealpha | pa | experimental = | alpha | a = | beta | b = | release | r | general | g | stable = | broken | br | unstable = }} }} }} }}
}}Template:Module rating/protected | other | #default = Template:Error }}}}
![]() | This module depends on the following other modules: |
Lua error in Module:TNT at line 159: Missing JsonConfig extension; Cannot load https://commons.wikimedia.org/wiki/Data:I18n/Uses TemplateStyles.tab.
Module:Infobox is a module that implements the Template:Tl template. Please see the template page for usage instructions.
{{#ifeq:Infobox|sandbox|| }}
-- Module:Infobox
-- A simplified Lua module to generate infobox tables for country data.
-- Refinements: Wikipedia-style header, Flag field, consistent row generation.
local p = {}
-- Helper function to preprocess Wikitext (e.g., for images, bullet lists)
local function preprocess_wikitext(text)
if text then
-- frame:preprocess() will expand templates, parser functions, and Wikitext syntax
-- It's crucial for turning [[File:...]] into actual images and * List into <ul><li>
return frame:preprocess(text)
end
return ''
end
-- Function to generate a single row in the infobox
local function makeRow(label, value)
if value and value ~= '' then
-- Preprocess the value to ensure Wikitext is rendered (e.g., [[Link]], * List)
return '|- \n! scope="row" | ' .. label .. ' \n| ' .. preprocess_wikitext(value) .. '\n'
else
return '' -- Return empty string if value is nil or empty
end
end
-- Main function to build the infobox
function p.main(frame)
local args = frame.args
-- Start the infobox table
local infobox_output = '{| class="infobox"\n'
-- Main Title/Caption (Official Name)
infobox_output = infobox_output .. '|+ ' .. preprocess_wikitext(args.official_name or 'Country Name') .. '\n'
-- Native Name Row (always present if native_name is provided, right after title)
infobox_output = infobox_output .. makeRow('Native Name', '​' .. args.native_name) -- ​ is zero-width space to ensure row renders even if native_name is just italics
-- Flag Image Section
if args.flag and args.flag ~= '' then
infobox_output = infobox_output ..
'|- \n| colspan="2" style="text-align: center; padding: 0.5em 0;" | \n' ..
preprocess_wikitext('[[File:' .. args.flag .. '|150px|center|alt=Flag of ' .. (args.official_name or 'Country') .. ']]') .. '\n'
end
-- Motto Row
infobox_output = infobox_output .. makeRow('Motto', args.motto)
-- Map Image Section
if args.map_image and args.map_image ~= '' then
local map_caption_text = ''
if args.map_caption and args.map_caption ~= '' then
map_caption_text = '<div class="infobox-map-caption">Official Borders & Territories Recognized.<br>' .. preprocess_wikitext(args.map_caption) .. '</div>'
end
infobox_output = infobox_output ..
'|- \n| colspan="2" style="text-align: center; padding: 0.5em 0;" | \n' ..
preprocess_wikitext('[[File:' .. args.map_image .. '|250px|center|alt=' .. (args.map_caption or 'Official Map') .. ']]') .. '\n' ..
map_caption_text .. '\n'
end
-- Add remaining rows based on provided parameters
infobox_output = infobox_output .. makeRow('Capital', args.capital)
infobox_output = infobox_output .. makeRow('Largest Cities', args.largest_cities)
infobox_output = infobox_output .. makeRow('Religious Identification', args.religious_identification)
infobox_output = infobox_output .. makeRow('Demonym', args.demonym)
infobox_output = infobox_output .. makeRow('Ethnic Groups', args.ethnic_groups)
infobox_output = infobox_output .. makeRow('Government', args.government)
infobox_output = infobox_output .. makeRow('Chambers', args.chambers)
infobox_output = infobox_output .. makeRow('Laws', args.laws)
infobox_output = infobox_output .. makeRow('Independence', args.independence)
infobox_output = infobox_output .. makeRow('Head of the State', args.head_of_state)
infobox_output = infobox_output .. makeRow('Power Status', args.power_status)
infobox_output = infobox_output .. makeRow('Common Background', args.common_background)
-- GDP section (nested list)
if (args.gdp_total and args.gdp_total ~= '') or (args.gdp_per_capita and args.gdp_per_capita ~= '') then
infobox_output = infobox_output .. '|- \n! scope="row" | GDP \n| \n'
if args.gdp_total and args.gdp_total ~= '' then
infobox_output = infobox_output .. preprocess_wikitext(': Total: ' .. args.gdp_total .. '\n')
end
if args.gdp_per_capita and args.gdp_per_capita ~= '' then
infobox_output = infobox_output .. preprocess_wikitext(': per Capita: ' .. args.gdp_per_capita .. '\n')
end
end
infobox_output = infobox_output .. makeRow('HDI', args.hdi)
infobox_output = infobox_output .. makeRow('Currency', args.currency)
infobox_output = infobox_output .. makeRow('Abbreviated Codex', args.codex)
-- End the infobox table
infobox_output = infobox_output .. '|}'
return infobox_output
end
return p