Initialize a new Template instance.
Name of the page that is to be transcluded. Should not contain anything but a page title.
Optional
config: TemplateConfigOptional initializer object.
When name
has inline \n
characters or when fullName
does not contain name
as a substring.
mediawiki.Title
mediawiki.util
Readonly
argsThe arguments of the template parsed as an array of objects.
Readonly
cleanname formatted by mw.Title.newFromText.
Readonly
fullReadonly
fullFull string that fits into the first slot of the template (i.e. {{fullName}}
). May be accompanied by additional
characters that are not relevant to the title of the page to be transcluded.
Protected
Readonly
hierarchyArgument hierarchies.
Readonly
keysAn array of the names of the template arguments.
Readonly
nameThe trimmed name
passed to the constructor.
Readonly
overriddenThe overridden arguments of the template stored as an array of objects.
Add new arguments to the Template instance. This method leaves a log when argument override takes place, which can be viewed by getOverriddenArgs.
An array of {name: string; value: string;}
objects.
Delete template arguments.
Deleted arguments.
Get (a deep copy of) a template argument by an argument name.
Argument name.
Optional
options: GetArgOptions & GetArgUniqueOptionsOptional search options.
null
if no argument is found with the specified name.
Get the arguments of the template as an array of objects.
Whether to return a deep copy, defaulted to true
. Otherwise, args is passed by reference
(not recommended).
Private
getCheck whether a given argument is to be hierarchically overridden.
Get the name of the template.
Optional
prop: "full" | "clean" | "fullclean"By default, returns the original, unformatted name
passed to Template.constructor.
full
is passed, returns fullName passed to Template.constructor
(same as name
if none was passed).clean
is passed, returns name that is formatted.fullclean
is passed, returns name that is formatted and accompanied by redundancies
as in fullName.In specifying any of the above, the first letter is capitalized.
Note that if name
is prefixed by Template:
, the namespace prefix is truncated in prop=clean
and prop=fullclean
.
// name: Template:test
const template = new Template('Template:test');
console.log(template.getName()): // Template:test
console.log(template.getName('full')): // Template:test
console.log(template.getName('clean')): // Test
console.log(template.getName('fullclean')): // Test
For the clean names, namespace aliases are formatted to their canonical ones.
// name: project:test', fullName: '<!--change?-->project:test
const template = new Template('project:test', {fullName: '<!--change?-->project:test'});
console.log(template.getName()): // project:test
console.log(template.getName('full')): // <!--change?-->project:test
console.log(template.getName('clean')): // Wikipedia:Test
console.log(template.getName('fullclean')): // <!--change?-->Wikipedia:Test
Get a list of overridden template arguments as an array of objects. This method returns a deep copy, and modifying the return value does not modify the original array stored in the class.
Check whether the Template instance has an argument with a certain name.
Name of the argument to search for.
Optional
options: GetArgOptionsOptional search options.
A boolean value in accordance with whether there is a match.
Private
registerNew argument object to register.
Whether to leave a log when overriding argument values.
Private
registerRender the Template instance as wikitext.
Use render({nameprop: 'full', unformatted: 'both'})
for an output that is closest to the original configurations.
Optional
options: RenderOptionsOptional object of rendering specifications
Set (or update) arguments in(to) the Template instance. This method does not leave a log when argument override takes place.
Note: New arguments are simply newly added, just as when addArgs is used.
An array of {name: string; value: string;}
objects.
Get class properties in a JSON format.
Stringify the Template instance. Same as render({nameprop: 'full', unformatted: 'both'})
.
Generated using TypeDoc
The Template class. Creates a new {{template}}.