Module:PageList

Jump to navigation Jump to search

Outputs a list of pages. Intended for use in notice templates.

Put {{#invoke:PageList|main}} in the template where you want the list to be. It will automatically work with as many unnamed parameters as needed.

Optional parameters:

  • conjunction: The conjunction used before the last article name. Defaults to "and". You can change it to "or" as follows: {{#invoke:PageList|main|conjunction=or}}
  • default: The text shown when no articles are linked to; defaults to showing "[[:{{{1}}}]]". You can change it to anything you want as follows: {{#invoke:PageList|main|default=multiple articles}}, {{#invoke:PageList|main|default=a different page title}}, etc.

These two optional parameters can both be used at the same time.


local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	local i = 1
	local conjunction = args["conjunction"] or "and"
	local defaultOutput = args["default"] or "[[:{{{1}}}]]"
	local output = ""
	if not args[1] then
		return defaultOutput
	end
	while args[i] do
		output = output .. "[[:" .. args[i] .. "]]"
		if args[i + 1] and args[i + 2] then
			output = output .. ", "
		elseif args[i + 1] then
			if (i + 1 == 2) then
				output = output .. " " .. conjunction .. " "
			else
				output = output .. ", " .. conjunction .. " "
			end
		end
		i = i + 1
	end
	output = string.gsub(output, "%[%[::", "[[:")
	return output
end

return p