Module:Wrapper
Jump to navigation
Jump to search
This module allows a template to pass all its arguments (both named and positional) to a subsequent template, simulating inheritance. It also allows the wrapper template to inject new arguments or override existing ones.
Usage
This module is intended to create wrapper templates such as {{smCharLink}}.
Basic Syntax
{{#invoke:Wrapper|pass
|_target_template_=Character link
|size=20}}
Parameters
- _target_template_ (Required): The exact name of the template you wish to invoke.
- Any other parameter defined in the
{{#invoke:}}block will be passed to the target template.
Precedence
If the wrapping template is passed a parameter with the same name, the value in the {{#invoke:}} block will override it. If this behavior is not desired, the following can be used instead to default to a passed argument over the predefined one.
{{#invoke:Wrapper|pass
|_target_template_=Character link
|size={{{size|20}}}
}}
-- Pass through arguments to a subsequent template with ammendments
local p = {}
function p.pass(frame)
local configArgs = frame.args
local pipedArgs = frame:getParent().args
local finalArgs = {}
for k, v in pairs(pipedArgs) do
finalArgs[k] = v
end
-- Injected arg are processed later, so they override
for k, v in pairs(configArgs) do
if k ~= '_target_template_' then
finalArgs[k] = v
end
end
return frame:expandTemplate{ title = configArgs['_target_template_'], args = finalArgs }
end
return p