Module:Navbox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 23: | Line 23: | ||
function make_box(title, groups) | function make_box(title, groups) | ||
local navbox = mw.html.create("table") | local navbox = mw.html.create("table"):addClass("navbox") | ||
-- Create title row | -- Create title row | ||
| Line 32: | Line 32: | ||
for _, group in ipairs(groups) do | for _, group in ipairs(groups) do | ||
local group_row = navbox:tag("tr"):addClass("group") | local group_row = navbox:tag("tr"):addClass("group") | ||
local content = "\n" .. group.content .. "\n" | |||
if group.name == nil then | if group.name == nil then | ||
group_row:tag("td"):attr("colspan", "2"):wikitext( | group_row:tag("td"):attr("colspan", "2"):wikitext(content) | ||
else | else | ||
group_row:tag("th"):wikitext(group.name) | group_row:tag("th"):wikitext(group.name) | ||
group_row:tag("td"):wikitext( | group_row:tag("td"):wikitext(content) | ||
end | end | ||
end | end | ||
Latest revision as of 03:47, 18 January 2021
Documentation for this module may be created at Module:Navbox/doc
local p = {}
function p.navbox(frame)
local title = frame.args.title
if title == nil then
error("Missing title")
end
-- Assign group1, group2, etc to groups
local groups = {}
local i = 1
while frame.args["group" .. i] ~= nil do
local group = {
content = frame.args["group" .. i],
name = frame.args["groupName" .. i] -- can be nil
}
table.insert(groups, group)
i = i + 1
end
return make_box(title, groups)
end
function make_box(title, groups)
local navbox = mw.html.create("table"):addClass("navbox")
-- Create title row
local title_row = navbox:tag("tr"):addClass("title")
title_row:tag("th"):attr("colspan", 2):wikitext(title)
-- Create row for each group
for _, group in ipairs(groups) do
local group_row = navbox:tag("tr"):addClass("group")
local content = "\n" .. group.content .. "\n"
if group.name == nil then
group_row:tag("td"):attr("colspan", "2"):wikitext(content)
else
group_row:tag("th"):wikitext(group.name)
group_row:tag("td"):wikitext(content)
end
end
return navbox
end
return p