Module:Hatnote list
Jump to navigation
Jump to search
Hatnote lists for some of the Hatnote templates.
local p = {}
function p.render(frame)
-- Get parent template (source of the numeric link arguments)
local parent = frame:getParent()
if not parent then
return "<strong class='error'>Error: No parent frame (preview mode)</strong>"
end
-- Collect link arguments from the template
local args = {}
for i = 1, 100 do
local v = parent.args[i]
if not v then break end
v = mw.text.trim(v)
if v ~= "" then
table.insert(args, v)
end
end
if #args == 0 then return "" end
-- Build wiki links
local links = {}
for _, page in ipairs(args) do
table.insert(links, "[[" .. page .. "]]")
end
-- Format list with commas and 'and'
local listText
if #links == 1 then
listText = links[1]
else
listText = table.concat(links, ", ", 1, #links - 1) .. " and " .. links[#links]
end
-- Optional pretext from the #invoke call
local pretext = frame.args["pretext"]
if not pretext or mw.text.trim(pretext) == "" then
pretext = "Further information:"
end
-- Wrap in Hatnote
return frame:expandTemplate{
title = "Hatnote",
args = { ["text"] = pretext .. " " .. listText }
}
end
return p