Module:Hatnote list
Jump to navigation
Jump to search
Currently used by {{Further}}, {{Main}} and {{Seealso}}, for making hatnotes.
Accepts both plain text and wikilinks as positional parameters: plain text will be turned into a link, wikilinks will be shown as is.
Parameter pretext specifies what text precedes link list, like "See also:" or "Further information:"
Usage
{{#invoke:Hatnote list|render}}
local p = {}
-- Check if text is already a wikilink
local function isWikilink(text)
return text:match("^%s*%[%[.+%]%]%s*$") ~= nil
end
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 links = {}
local i = 1
while parent.args[i] do
local v = mw.text.trim(parent.args[i])
if v ~= "" then
if isWikilink(v) then
table.insert(links, v)
else
table.insert(links, "[[" .. v .. "]]")
end
end
i = i + 1
end
if #links == 0 then return "" 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 template
return frame:expandTemplate{
title = "Hatnote",
args = { pretext .. " " .. listText }
}
end
return p