Module:Template wrapper/doc

&#x3c;!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see Wikidata) --&#x3e;

This module is to be used in wrapper templates to allow those templates to provide default parameter values and allow editors to pass additional parameters to the underlying working template.

When writing a wrapper template, give this module all of the normally required default parameters necessary to use the wrapper template in its base form. Editors then use the wrapper template as-is or may supply additional wrapper and canonical parameters. Any of the canonical parameters supported by the working template may be added to the wrapper template or supplied by editors in article space. When an editor supplies a parameter that has a default value in the wrapper template, the editor-supplied value overrides the default. When it is necessary to remove a default parameter, editors may set the parameter value to the special keyword &#x3c;code&#x3e;unset&#x3c;/code&#x3e; which will cause this wrapper module to erase the wrapper template's default value for that parameter. This module discards empty named parameters.

Positional parameters are not normally passed on to the working template. Setting yes will pass all positional parameters to the working template. Positional parameters cannot be excluded; positional parameters may be &#x3c;code&#x3e;unset&#x3c;/code&#x3e;.

Parameters that are used only by the wrapper should be either positional or listed in _exclude (a comma-separated list of named parameters). This module will not pass &#x3c;code&#x3e;_excluded&#x3c;/code&#x3e; parameters to the working template.

Usage
&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/code&#x3e;


 * Control parameters
 * _template – (required) the name, without namespace, of the working template (the template that is wrapped); see §_template below
 * _exclude – comma-separated list of parameter names used by the wrapper template that are not to be passed to the working template; see §_exclude below
 * _reuse – comma-separated list of canonical names that have meaning to both the wrapper template and to the working template; see §_reuse below
 * _alias-map – comma-separated list of wrapper-template parameter names that are to be treated as aliases of specified working template canonical parameters; see §_alias-map below
 * _include-positional – pass all positional parameters to the working template; see §_include-positional below


 * Definitions
 * canonical parameter – a parameter supported and used by the working template
 * wrapper parameter – a parameter used by the wrapper template; may provide data for canonical parameters or control other aspects of the wrapper template
 * alias parameter – a wrapper parameter that is contextually meaningful to the wrapper template but must be renamed to a canonical parameter for use by the working template
 * reused parameter – a parameter that is shared by both wrapper and working templates and has been modified by wrapper template
 * default parameter – a canonical parameter given a default value in the wrapper template

_template
The only required parameter, _template supplies the name, without namespace, of the working template (the template that is wrapped). If this parameter is omitted, Module:Template wrapper will emit the error message:
 * &#x3c;span style="font-size:100%" class="error"&#x3e;&#x3c;code style="color:inherit; border:inherit; padding:inherit;"&#x3e;&#x26;#124;_template=&#x3c;/code&#x3e; missing or empty&#x3c;/span&#x3e;

_alias-map
_alias-map takes a comma-separated list of wrapper-template parameters that are to be treated as aliases of specified working template canonical parameters. Each mapping element of the list has the form:
 * &#x3c;code&#x3e;&#x26;lt;from&#x3e;:&#x26;lt;to&#x3e;&#x3c;/code&#x3e; – where: &#x3c;code&#x3e;&#x26;lt;from&#x3e;&#x3c;/code&#x3e; is a wrapper parameter name and &#x3c;code&#x3e;&#x26;lt;to&#x3e;&#x3c;/code&#x3e; is a canonical parameter name

In this example, it may be preferable for a wrapper template to use assessor which may be unknown to the working template but the working template may have an equivalent author so in the &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; we would write:
 * assessor:author

Positional parameters may also be mapped to canonical parameters:
 * 1:author, 2:title, 3:language

Enumerated wrapper parameters may be mapped to enumerated canonical parameters using the &#x3c;code&#x3e;#&#x3c;/code&#x3e; enumerator specifier:
 * assessor#:author#

Given the above example, assessor2 will map to author2; also, assessor and assessor1 will map to author1

Multiple wrapper parameters can map to a single canonical parameter:
 * 1:author, assessor:author

Wrapper parameters listed in alias-map are not passed to the working template. Mapping positional parameters when yes may give undesirable results. 1:author and yes will cause all other positional parameters to be passed to the working template as is: wrapper template &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; becomes working template &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;, etc; working template will not get &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; though it will get author.

_reuse
_reuse takes a comma-separated list of canonical parameters that have meaning to both the wrapper template and to the working template

In the simplest cases, a canonical parameter passed into the wrapper template overrides a default parameter provided in the wrapper template. Sometimes a wrapper parameter is the same as a canonical parameter and the wrapper template needs to modify the parameter value before it is passed to the working template. In this example, title is both a wrapper parameter and a canonical parameter that the wrapper template needs to modify before passing to the working template. To do this we first write:
 * title

then, in the wrapper template's &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; we write:
 * Modified &#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;

_reused parameters cannot be overridden.

_exclude
_exclude takes a comma-separated list of parameters used by the wrapper template that are not to be passed to the working template. This list applies to all wrapper and canonical parameters (including those canonical parameters that are renamed alias parameters) received from the wrapper template.

As an example, a wrapper template might use id to supply a portion of the value assigned to default parameter url so we would write:
 * id

then, in the wrapper template's &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; we write:
 * &#x3c;nowiki&#x3e;https://example.com/&#x3c;/nowiki&#x3e;

The modified url value is passed on to working template but id and its value is not.

_reused and default parameters cannot be excluded.

_include-positional
_include-positional is a boolean parameter that takes only one value: &#x3c;code&#x3e;yes&#x3c;/code&#x3e;; the default (empty, missing) is &#x3c;code&#x3e;no&#x3c;/code&#x3e; (positional parameters normally excluded). When set to &#x3c;code&#x3e;yes&#x3c;/code&#x3e;, Module:Template wrapper will pass all positional parameters to the working template.

See also §_alias-map.

Overriding default parameters
Editors may override default parameters by simply setting the default parameter to the desired value in the wrapper template. This module ignores empty parameters (those parameters that are named but which do not have an assigned value). When it is desirable to override a default parameter to no value, use the special keyword &#x3c;code&#x3e;unset&#x3c;/code&#x3e;. Default parameters with this value are passed to the working template as empty (no assigned value) parameters.

_reused parameters cannot be &#x3c;code&#x3e;unset&#x3c;/code&#x3e; or overridden.

Debugging/documentation mode
This module has two entry points. A wrapper template might use a module &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; written like this:
 * &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/code&#x3e;

where the _debug wrapper parameter, set to any value, will cause the module to render the call to the working template without actually calling the working template.

As an example, is a wrapper template that uses  as its working template. accepts positional parameters but does not so the wrapper template must convert the positional parameters to named parameters which it does using the _alias-map parameter:
 * &#x3c;syntaxhighlight lang="moin"&#x3e;{{#invoke:template wrapper|{{#if:{{{_debug|}}}|list|wrap}}|_template=citation

|_exclude=..., _debug &#x3c;!-- unnecessary detail omitted --&#x3e; |_alias-map=1:title, 2:author, 3:language&#x3c;/syntaxhighlight&#x3e; This example uses positional parameters and sets {{para|_debug|yes}} to show that the template is correctly formed:
 * &#x3c;code&#x3e;&#x3c;nowiki&#x3e;{{cite wikisource|Sentido y sensibilidad|Jane Austen|es|_debug=yes}}&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;
 * {{cite wikisource|Sentido y sensibilidad|Jane Austen|es|_debug=yes}}

and, with _debug unset:
 * &#x3c;code&#x3e;&#x3c;nowiki&#x3e;{{cite wikisource|Sentido y sensibilidad|Jane Austen|es|_debug=}}&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;
 * {{cite wikisource|Sentido y sensibilidad|Jane Austen|es|_debug=}}

The {{para|_debug}} name is chosen here for convenience but may be anything so long as it matches the &#x3c;code&#x3e;&#x3c;nowiki&#x3e;{{#if:}}&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; in the &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;.

You may also call the &#x3c;code&#x3e;link&#x3c;/code&#x3e; function to get something like the left-hand side of Template:yy. This is essentially the &#x3c;code&#x3e;list&#x3c;/code&#x3e; function with the template name turned into a link. {{yytop|headers=no}} {{yy|User in New Zealand|4}} {{yybottom}}

&#x3c;includeonly&#x3e;{{sandbox other|| &#x3c;!-- Categories below this line, please; interwikis at Wikidata --&#x3e;

}}&#x3c;/includeonly&#x3e;