Extension:Closures

Category:Extensions without an imageCategory:GPL licensed extensions
MediaWiki extensions manual
Closures
Release status: stableCategory:Stable extensions
Implementation Parser extension Category:Parser extensions
Description Provides a way for users to define templates on the page they are needed through a parser function.
Author(s) Xxmarijnw
Latest version 1.1.0 (2021-03-21)
Compatibility policy Master maintains backward compatibility.Category:Extensions with master compatibility policy
MediaWiki 1.35+Category:Extensions with manual MediaWiki version
PHP 7.4+
License GNU General Public License 2.0 or later
Download Category:Extensions in GitHub version control
Category:All extensions

The Closures extension provides a way for users to define templates on the page they are needed through a parser function. This is especially useful combination with parser functions that take the name of a template as a parameter and use that for outputting data.

Usage

The extension defines the parser function {{#closure}}. The text before the first pipe in this parser function will become the name of the closure and everything after that becomes the body of the closure. This means that escaping pipes in the body is not necessary.

A closure acts exactly like a regular template. This means it is possible to use template variables, templates, parser functions and even other closures in a closure. This also means closures can be transcluded on the page using regular templating syntax.

Furthermore, closures allow you to override existing templates with custom behaviour by defining a closure with the same name as an existing template.

Example

Below is this example from Semantic MediaWiki, adapted to use closures instead:

{{#closure: TableHeader |
{| class="wikitable"
 ! City !! Population !! Area
 |-
}}

{{#closure: TableBody |
 | {{{1}}} || {{{2}}} || {{{3}}}
 |-
}}

{{#closure: TableFooter |
|}
}}

{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 |?Population
 |?Area
 |format=plainlist
 |introtemplate=TableHeader
 |template=TableBody
 |outrotemplate=TableFooter
}}

Installation

  • Download and place the file(s) in a directory called Closures in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Closures' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Category:All extensions Category:Extensions in GitHub version control Category:Extensions with manual MediaWiki version Category:Extensions with master compatibility policy Category:Extensions without an image Category:GPL licensed extensions Category:ParserFirstCallInit extensions Category:ParserOptionsRegister extensions Category:Parser extensions Category:Stable extensions