Module:Template wrapper/doc

MyWikiBiz, Author Your Legacy — Friday November 29, 2024
< Module:Template wrapper
Revision as of 07:36, 16 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This is the documentation page for Module:Template wrapper


Template:High-use

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 unset 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 Template:Para will pass all positional parameters to the working template. Positional parameters cannot be excluded; positional parameters may be unset.

Parameters that are used only by the wrapper should be either positional (Template:Param) or listed in Template:Para (a comma-separated list of named parameters). This module will not pass _excluded parameters to the working template.

Usage

{{#invoke:Template wrapper|wrap|_template=Template:Var|_exclude=Template:Var, Template:Var, ...|_reuse=Template:Var, Template:Var, ...|_alias-map=Template:Var:Template:Var|_include-positional=yes|<Template:Var>|<Template:Var>|...}}

Control parameters
Template:Para – (required) the name, without namespace, of the working template (the template that is wrapped); see §_template below
Template:Para – comma-separated list of parameter names used by the wrapper template that are not to be passed to the working template; see §_exclude below
Template:Para – comma-separated list of canonical names that have meaning to both the wrapper template and to the working template; see §_reuse below
Template:Para – 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
Template:Para – 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
parameter processing
wrapper
template
Module:Template wrapper working
template
Template:Para  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  →  filter
exclued
parameters
working
template
Template:Para  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  → 
  Template:Para  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  →   → 
  Template:Para  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  → 
  Template:Para  →  convert alias
parameters to
canonical
parameters
 →  Template:Para  →  –––––––→  →  –––––––→  →   → 
   →   →  modify
reused
canonical
parameters
Template:Para  →  –––––––→  →   →  Template:Para  →  –––→  → 
  Template:Para  →  –––––––→  →  –––––––→  → 
Template:Para  →  –––––––→  →  –––––––→  →  –––––––→  → 
  Template:Para  →  –––––––→  →  –––––––→  →  –––––––→  →  –––––––→  →  –––→  → 

Parameter details

_template

The only required parameter, Template:Para 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:

|_template= missing or empty

_alias-map

Template:Para 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:

<Template:Var>:<Template:Var> – where: <Template:Var> is a wrapper parameter name and <Template:Var> is a canonical parameter name

In this example, it may be preferable for a wrapper template to use Template:Para which may be unknown to the working template but the working template may have an equivalent Template:Para so in the {{#invoke:}} we would write:

Template:Para

Positional parameters may also be mapped to canonical parameters:

Template:Para

Enumerated wrapper parameters may be mapped to enumerated canonical parameters using the # enumerator specifier:

Template:Para

Given the above example, Template:Para will map to Template:Para; also, Template:Para and Template:Para will map to Template:Para

Multiple wrapper parameters can map to a single canonical parameter:

Template:Para

Wrapper parameters listed in Template:Para are not passed to the working template. Mapping positional parameters when Template:Para may give undesirable results. Template:Para and Template:Para will cause all other positional parameters to be passed to the working template as is: wrapper template {{{2}}} becomes working template {{{2}}}, etc; working template will not get {{{1}}} though it will get Template:Para.

_reuse

Template:Para 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, Template:Para 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:

Template:Para

then, in the wrapper template's {{#invoke:Template wrapper|wrap|_template=...|...}} we write:

Template:Para

_reused parameters cannot be overridden.

_exclude

Template:Para 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 Template:Para to supply a portion of the value assigned to default parameter Template:Para so we would write:

Template:Para

then, in the wrapper template's {{#invoke:Template wrapper|wrap|_template=...|...}} we write:

Template:Para

The modified Template:Para value is passed on to working template but Template:Para and its value is not.

_reused and default parameters cannot be excluded.

_include-positional

Template:Para is a boolean parameter that takes only one value: yes; the default (empty, missing) is no (positional parameters normally excluded). When set to yes, 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 unset. Default parameters with this value are passed to the working template as empty (no assigned value) parameters.

_reused parameters cannot be unset or overridden.

Debugging/documentation mode

This module has two entry points. A wrapper template might use a module {{#invoke:}} written like this:

{{#invoke:Template wrapper|{{#if:{{{_debug|}}}|list|wrap}}|_template=<Template:Var>|_exclude=_debug, ...|...}}

where the Template:Para 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, Template:Tlx is a wrapper template that uses Template:Tlx as its working template. Template:Tld accepts positional parameters but Template:Tld does not so the wrapper template must convert the positional parameters to named parameters which it does using the Template:Para parameter:

<syntaxhighlight lang="moin">{{#invoke:template wrapper|wrap|_template=citation
 |_exclude=..., _debug 
 |_alias-map=1:title, 2:author, 3:language</syntaxhighlight>

This example uses positional parameters and sets Template:Para to show that the Template:Tld template is correctly formed:

{{cite wikisource|Sentido y sensibilidad|Jane Austen|es|_debug=yes}}
Template:Cite wikisource

and, with Template:Para unset:

{{cite wikisource|Sentido y sensibilidad|Jane Austen|es|_debug=}}
Template:Cite wikisource

The Template:Para name is chosen here for convenience but may be anything so long as it matches the {{#if:}} in the {{#invoke:}}.

You may also call the link function to get something like the left-hand side of Template:yy. This is essentially the list function with the template name turned into a link. Template:Yytop Template:Yy Template:Yybottom