Extension:Closures

The Closures extension provides a way for users to define templates through a parser function on the page they are needed. 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. 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.

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 | }}