Module:CallTemplate/doc

From Angelina Jordan Wiki
Revision as of 22:55, 6 September 2025 by Dcljr (talk | contribs) (doc created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:CallTemplate

This module and its documentation are slightly modified versions what Google's AI Overview returned for the prompt "simple Lua module to call a MediaWiki template for any number of input parameters". They will both be improved "soon".

Explanation

  • local p = {}: Initializes an empty table p which will hold the module's functions.
  • function p.call(frame): Defines a function call within the table p. This function will be called by {{#invoke:CallTemplate|call}}. The frame object provides access to arguments and other MediaWiki functionalities.
  • local args = frame.args: Retrieves the arguments passed to the {{#invoke:}} call as a table.
  • local templateName = args[1]: Assumes the first positional argument is the name of the template to be called.
  • local templateArgs = {}: Creates an empty table to store the arguments intended for the target template.
  • for i, v in ipairs(args) do ... end: Iterates through the arguments passed to the module. It skips the first argument (the template name) and adds the rest to templateArgs.
  • local templateCall = "{{" .. templateName ... "}}": Constructs the wikitext string for the template call, dynamically adding the arguments.
  • return frame:preprocess(templateCall): This is the core of calling the template. frame:preprocess() instructs MediaWiki to parse and expand the provided wikitext string, effectively calling the specified template with the collected arguments.

Usage in Wikitext

Code

{{#invoke:CallTemplate|call|MyTemplate|Parameter1|Parameter2|NamedParameter=Value}}

This example would call Template:MyTemplate with Parameter1, Parameter2, and NamedParameter=Value as its arguments.

end of Google's output