Broken/wikipedia:Wrapper templates
This help page is a how-to guide. It details processes or procedures of some aspect(s) of Wikipedia's norms and practices. It is not one of Wikipedia's policies or guidelines, as it has not been thoroughly vetted by the community. | {| id="shortcut" class="noprint" style="border: 1px solid #999; background: #fff; margin: 0 0 .5em 1em; text-align: center; padding: 5px; float: right; clear: right; font-size: smaller;"
|-
! Shortcut: |
Wrapper templates are outer templates which wrap around simpler inner templates, to greatly extend the basic functionality of the inner templates. The concept is to structure the underlying, inner templates to be used as utility tools by various outer, wrapper templates.
Experience has shown that, when the underlying templates have been restructured with a full set of options to be used, then numerous variations of wrapper templates have been created to extend template functionality with a broad variety of new features.
Wrapper templates can be useful for consolidation, as they allow templates to build off of each other, whereas copying and pasting templates can make them harder to maintain.
A simple example
The function of Template:Exams is to place a box on one's userpage stating that one is taking a wikibreak to focus on exams. A more general template for wikibreaks, Template:Wikibreak, already exists, so rather than duplicating it, {{Exams}} just consists of a call of {{Wikibreak}} with some parameters specified, such as an image of books rather than the default image of a sunset.
An example with substitution
Template:Don't ping inserts a message on a talk page that one is following the page and doesn't need to be pinged in replies. It calls Template:Please ping with the no
parameter specified. This gets a little trickier because {{Don't ping}} may be substituted. To address this, the actual code used is {{safesubst:<noinclude/>Please ping|no}}
.
Wrappers around Lua modules
Many templates, such as {{if empty}} or {{infobox}}, are just simple wrappers around Lua modules, in this case Module:If empty and Module:Infobox. This is straightforward to implement as the frame:getParent().args
table in Lua, which is accessed from the module, can directly read the arguments passed to the wrapper template. The template can then be as simple as {{#invoke:If empty|main}}
(although there is slightly more code to make it substable and add documentation). Two of the main points of this are to avoid needing the "{{#invoke:" syntax in articles, and backward compatibility.
Templates
- {{uses Infobox person}}
- {{wrapper}}
- {{wrapper template}}
- {{wraps infobox}}