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
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.