Extension:Closures
Closures Release status: stable |
|
---|---|
Implementation | Parser extension |
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. |
MediaWiki | 1.35+ |
PHP | 7.4+ |
License | GNU General Public License 2.0 or later |
Download | GitHub: Note: |
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
editThe 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
editBelow 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
edit- Download and place the file(s) in a directory called
Closures
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'Closures' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.