Class Template

The Template class. Creates a new {{template}}.

Hierarchy

Constructors

  • Initialize a new Template instance.

    Parameters

    • name: string

      Name of the page that is to be transcluded. Should not contain anything but a page title.

    • Optional config: TemplateConfig

      Optional initializer object.

    Returns Template

    Throws

    When name has inline \n characters or when fullName does not contain name as a substring.

    Requires

    mediawiki.Title

    Requires

    mediawiki.util

Properties

The arguments of the template parsed as an array of objects.

cleanName: string

name formatted by mw.Title.newFromText.

fullCleanName: string

cleanName with redundancies as in fullName.

fullName: string

Full 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.

hierarchy: string[][]

Argument hierarchies.

keys: string[]

An array of the names of the template arguments.

name: string

The trimmed name passed to the constructor.

overriddenArgs: TemplateArgument[]

The overridden arguments of the template stored as an array of objects.

Methods

  • Delete a template argument.

    Parameters

    • name: string

    Returns boolean

    true if the instance has an argument with the specified name and if the argument is successfully removed, false otherwise.

  • Get the arguments of the template as an array of objects.

    Parameters

    • deepCopy: boolean = true

      Whether to return a deep copy, defaulted to true. Otherwise, args is passed by reference (not recommended).

    Returns TemplateArgument[]

  • Get the argument hierarchies.

    Returns string[][]

  • Get the name of the template.

    Parameters

    • Optional prop: "full" | "clean" | "fullclean"

      By default, returns the original, unformatted name passed to Template.constructor.

      • If full is passed, returns fullName passed to Template.constructor (same as name if none was passed).
      • If clean is passed, returns name that is formatted.
      • If 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

    Returns string

  • 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.

    Returns TemplateArgument[]

  • Check whether the Template instance has an argument with a certain name.

    Parameters

    • name: string | RegExp

      Name of the argument to search for.

    • Optional options: GetArgOptions

      Optional search options.

    Returns boolean

    A boolean value in accordance with whether there is a match.

  • Parameters

    • arg: TemplateArgument

      New argument object to register.

    • logOverride: boolean

      Whether to leave a log when overriding argument values.

    Returns void

  • Register template arguments into args.

    Parameters

    • newArgs: NewArg[]

      An array of {name: string; value: string;} objects.

    • logOverride: boolean

      Whether to leave a log when overriding argument values.

    Returns void

  • Render the Template instance as wikitext.

    Use render({nameprop: 'full', unformatted: 'both'}) for an output that is closest to the original configurations.

    Parameters

    • Optional options: RenderOptions

      Optional object of rendering specifications

    Returns string

  • 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.

    Parameters

    • newArgs: NewArg[]

      An array of {name: string; value: string;} objects.

    Returns Template

  • Stringify the Template instance. Same as render({nameprop: 'full', unformatted: 'both'}).

    Returns string

Generated using TypeDoc