Module:InfoboxBasic: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- | -- Render all remaining named params in the order they were supplied | ||
local | local skip = { | ||
name=true, Name=true, title=true, Title=true, | |||
image=true, Image=true, | |||
color=true, Color=true, colour=true, Colour=true, | |||
class=true, style=true | |||
} | |||
function | local function addRow(label, value) | ||
local | local row = tbl:tag('tr') | ||
row:tag('th'):attr('scope','row'):wikitext(labelFromKey(label)) | |||
row:tag('td'):wikitext(value) | |||
end | |||
if parent and parent.getArgumentPairs then | |||
-- This preserves the author’s order | |||
for key, value in parent:getArgumentPairs() do | |||
if not skip[key] and not tonumber(key) and not isBlank(value) then | |||
addRow(key, value) | |||
end | |||
end | end | ||
else | |||
-- | -- Fallback (older MW): order may not be preserved | ||
local names = {} | local names = {} | ||
for k,_ in pairs(args) do table.insert(names, k) end | |||
-- do NOT sort; keep whatever order Lua gives us | |||
for _, key in ipairs(names) do | for _, key in ipairs(names) do | ||
if not skip[key] and not tonumber(key) then | if not skip[key] and not tonumber(key) then | ||
local v = args[key] | local v = args[key] | ||
if not isBlank(v) then | if not isBlank(v) then addRow(key, v) end | ||
end | end | ||
end | end | ||
end | end | ||
Revision as of 22:50, 1 October 2025
Documentation for this module may be created at Module:InfoboxBasic/doc
-- Render all remaining named params in the order they were supplied
local skip = {
name=true, Name=true, title=true, Title=true,
image=true, Image=true,
color=true, Color=true, colour=true, Colour=true,
class=true, style=true
}
local function addRow(label, value)
local row = tbl:tag('tr')
row:tag('th'):attr('scope','row'):wikitext(labelFromKey(label))
row:tag('td'):wikitext(value)
end
if parent and parent.getArgumentPairs then
-- This preserves the author’s order
for key, value in parent:getArgumentPairs() do
if not skip[key] and not tonumber(key) and not isBlank(value) then
addRow(key, value)
end
end
else
-- Fallback (older MW): order may not be preserved
local names = {}
for k,_ in pairs(args) do table.insert(names, k) end
-- do NOT sort; keep whatever order Lua gives us
for _, key in ipairs(names) do
if not skip[key] and not tonumber(key) then
local v = args[key]
if not isBlank(v) then addRow(key, v) end
end
end
end