-- This module implements template link templates like {{tlx}}, {{tlu}} and {{tlp}} that take many parameters.
-- The module attempts to display named parameters as best it can, although the order will not be preserved.
-- Templates that take only one or two parameters, such as {{tl}}, are not implemented, as they will give
-- better performance as regular templates.
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function makeInvokeFunction(funcName)
	return function (frame)
		local args = getArgs(frame, {trim = false, removeBlanks = false})
		return p[funcName](args)
function p.constructInvocation(targs, data)
	-- Builds a template invocation from the template args (targs).
	-- The algorithm is a modified version of the one used in [[Module:Unsubst]].
	local nowiki = mw.text.nowiki -- If this is used we will call it for every argument, so making it local to improve performance.
	local cleanVal
	if data.nowiki then
		cleanVal = function (v)
			return nowiki(v)
		cleanVal = function (v)
			return v
	-- Define the most common escaped characters.
	local pipe = '|'
	local equals = '='
	local leftBrackets = '{{'
	local rightBrackets = '}}'
	-- Work out what the template link should be.
	local template = data.template
	if not template then
		error('Template name not specified', 2)
	if then
		template = mw.ustring.format('[[Template:%s|%s]]', template, template)
	-- Process numbered args.
	local ret = leftBrackets .. template
	for k, v in ipairs(targs) do
		if string.find(v, '=', 1, true) then
			-- Likely something like 1=foo=bar, so we need to do it as a named arg.
		ret = ret .. pipe .. cleanVal(v)
		targs[k] = nil
	-- Process named args.
	for k, v in pairs( targs ) do
		ret = ret .. pipe .. cleanVal(k) .. equals .. cleanVal(v)
	return ret .. rightBrackets
return p

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.