The indices of the child objects within the parseTemplates result array.
The ending index of this double-braced markup in the wikitext (exclusive).
The index of this object within the result array returned by parseTemplates.
The nesting level of this double-braced markup. 0
if not nested within another double-braced expression.
Readonly
paramsThe template's parameters.
This property is read-only. To update it, use insertParam, updateParam, or deleteParam as per your needs.
The index of the parent object within the parseTemplates result array,
or null
if there is no parent.
The raw template title, as directly parsed from the first operand of a {{template|...}}
expression.
Whether the double-braced markup appears inside an HTML tag specified in SkipTags.
The starting index of this double-braced markup in the wikitext.
The original text of the double-braced markup parsed from the wikitext. The value of this property is static.
Readonly
titleThe template's title.
This property is read-only. To update it, use setTitle.
Deletes a parameter from the template.
The parameter key to delete.
Optional
resolveHierarchy: booleanWhether to consider hierarchies when
resolving the key. If true
, this method checks the params object for any parameter whose key is
an alias of key
and deletes it if found. (Default: false
)
true
if a matching parameter was deleted; otherwise, false
.
Gets a parameter object by key.
Caution: The returned object is mutable.
The parameter key.
Optional
resolveHierarchy: booleanWhether to consider hierarchies when
searching for a matching parameter. If true
, this method first checks whether key
belongs to a hierarchy
array. If params contains a parameter with a higher-priority key in that hierarchy, that parameter
is returned instead. (Default: false
).
Example:
key = '1'
, hierarchies = [['1', 'user', 'User']]
, and params
containing a parameter keyed 'user'
,
this method returns the 'user'
parameter.If key
does not belong to any hierarchy array, the method behaves the same as when
resolveHierarchy
is false
. This also applies if no template parameter hierarchies have been provided
via the constructor or ParseTemplatesConfig.hierarchies.
The parameter object if found; otherwise, null
.
Checks if a template parameter with the specified key exists, optionally matching its value.
The parameter key to match, either as an exact string or a regular expression.
Optional
value: string | RegExpThe optional value matcher.
true
if a matching parameter exists; otherwise, false
.
Checks if a template parameter exists based on a custom predicate function.
A function that tests each parameter.
true
if a matching parameter exists; otherwise, false
.
Inserts a template parameter into the list.
By default, if the parameter is new:
position
is specified, the insertion position is controlled accordingly.If a parameter with the same key
already exists:
overwrite
is true
(default):
position
is not specified, the parameter’s value is updated in place (its position remains unchanged).position
is specified, the parameter’s value is updated and moved to the specified position.overwrite
is false
, the existing parameter is left unchanged and no insertion occurs.If parameter hierarchies are set, key
is automatically
resolved to the higher-priority key, if applicable.
Note that the order of parameters in the final output can also be controlled via stringify, using TemplateOutputConfig.sortPredicate, regardless of the insertion order tracked by this instance.
The key of the parameter. This can be an empty string for unnamed parameters.
The value of the parameter.
Optional
overwrite: booleanWhether to overwrite an existing parameter if it exists. (Default: true
)
Optional
position: { before: string } | { after: string } | "start" | "end"Where to insert or move the parameter:
'start'
: Insert at the beginning.'end'
: Insert at the end (default for new parameters).{ before: referenceKey }
: Insert before the given key.{ after: referenceKey }
: Insert after the given key.If referenceKey
does not exist:
'end'
.position
is not specified).When specifying a referenceKey
, it is best practice to verify its existence beforehand to ensure
expected behavior. See hasParam for the relevant utility.
The current instance for chaining.
Sets a new title to the instance.
This method simply updates the title property of the instance. If the new title is an unambiguously valid title for MediaWiki, use toTemplate or toParserFunction instead.
The new title to set.
The current instance for chaining.
Stringifies the instance.
Optional
options: RawTemplateOutputConfigOptions to format the output.
The template as a string.
Sets a valid function hook and converts the instance to a new ParsedParserFunction instance.
The conversion is based on the data used to initialize this instance, and any modifications made after initialization will be discarded. Therefore, this method should be called before making any changes to the instance properties.
The parser function hook to convert this title to, including a trailing
colon character (e.g., "#if:"
; see also ParserFunctionStatic.verify). If a Title
instance is passed, the output of title.getPrefixedDb({ colon: true, fragment: true })
is validated.
When passing a string, it can (and should) include the function’s first parameter (e.g., '#if:1'
).
The second and subsequent parameters are initialized based on params.
Whether to log errors (default: false
).
A new ParsedParserFunction instance on success; otherwise, null
.
Sets a valid template title and converts the instance to a new ParsedTemplate instance.
The conversion is based on the data used to initialize this instance, and any modifications made after initialization will be discarded. Therefore, this method should be called before making any changes to the instance properties.
The new template title to set.
Optional
verbose: booleanWhether to log errors. (Default: false
)
A new ParsedTemplate instance on success; otherwise, null
.
Updates the value of an existing parameter without changing its position.
key
exists, this method does nothing.key
is automatically
resolved to the higher-priority key, if applicable.This is functionally equivalent to calling insertParam with overwrite = true
and no position
,
except that it performs no operation if the parameter does not already exist.
Use this method when you want to safely update a parameter only if it exists, without affecting the order of parameters or accidentally inserting new ones.
The key of the parameter. This can be an empty string for unnamed parameters.
The new value of the parameter.
The current instance for chaining.
The instance members of the
RawTemplate
class. For static members, see RawTemplateStatic (defined separately due to TypeScript limitations).