Wikipedia:Wrapper templates
![]() | This help page is a how-to guide. It explains concepts or processes used by the Wikipedia community. It is not one of Wikipedia's policies or guidelines, and may reflect varying levels of consensus. |
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. Templates can be wrapped to existing templates with Module:Template wrapper.
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
[edit]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
[edit]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
[edit]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
[edit]- {{uses infobox person}}
- {{wrapper}}
- {{wraps infobox}}
- {{CS1 wrapper}}