Module:Template wrapper positional
This is a simplified version of Module:Template wrapper that handles positional arguments better.
Syntax:
{{#invoke:Template wrapper positional|main|_template=template|_offset=offset|...extra_args}}
All args other than "_template" and "_offset" are passed unchanged to the parent template, including positional ones. Any numbered arguments are subtracted by the offset param.
This has two sets of use cases. The first is for a template to consume one (or more) positional params and forward the others somewhere else:
For example, if Template:Foo said:
{{#invoke:Template wrapper positional|main|_template=Bar|_offset=1|baz={{{1}}}}}
,
{{foo|a|b|c|quux=123}}
would turn in to:
{{Bar|b|c|baz=a|quux=123}}
The second use case is for a template to modify a positional param and pass the rest unchanged (Module:Template wrapper can't do this since it ignores positional params from the frame). For example, if Template:Foo said:
{{#invoke:Template wrapper positional|main|_template=Bar|This is param 1: {{{1}}}}}
{{foo|a|b|c|quux=123}}
would turn in to:
{{Bar|This is param 1: a|b|c|quux=123}}
local p = {}
function p.main(frame)
local newArgs = {}
local temp = frame.args["_template"]
local offset = frame.args["_offset"] or 0
for k, v in pairs(frame:getParent().args) do
if type(k) == "number" then
k = k - offset
end
newArgs[k] = v
end
for k, v in pairs(frame.args) do
if k ~= "_template" and k ~= "_offset" then
newArgs[k] = v
end
end
if temp then
return frame:expandTemplate{title=temp, args=newArgs}
else
error("_template arg is required")
end
end
return p