Extension:TemplateFunc

Category:Extensions without an imageCategory:Extensions without a compatibility policyCategory:GPL licensed extensions
MediaWiki extensions manual
TemplateFunc
Release status: stableCategory:Stable extensions
Implementation Parser function Category:Parser function extensions
Description Convert structured data from wiki pages to other data formats
Author(s) DG
Latest version 0.4
MediaWiki 1.39+Category:Extensions with manual MediaWiki version
  • $wgTFDoPurge
  • $wgMustacheTemplatesDir
Licence GNU General Public License 3.0 or later
Download Category:Extensions in GitHub version control
Category:All extensionsCategory:Extensions not in ExtensionJson

The TemplateFunc extension offers parser functions for fetching structured data from wiki pages and converting them to other data formats for use in the wiki, including wiki template markup, JSON, Mustache templates and Smarty widgets.

It was specifically created to work with multiple-instance templates and to offer solutions to issues that are expected to arise in the future as Parsoid takes over as the de facto MediaWiki parser. It may be useful, too, if the use of Lua/Scribunto is not allowed on your wiki's server.

This extension is developed and maintained for CODECS, a Semantic MediaWiki-driven wiki for Celtic studies.

Installation

  • Download and place the file(s) in a directory called TemplateFunc in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'TemplateFunc' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

The extension comes with two parser functions :

  • #tf-convert - the main parser function, which allows you to read a template's data on a wiki page and re-assign those data to a different format, such as a different wiki template, Smarty widget or JSON representation.
  • #tf-mustache - a dedicated parser function for using Mustache templates.

See Github for more details.

Example

Example of using #tf-convert to fetch data from a wiki page ('My Recipe for Grilled Chipotle Tofu'), more specifically instances of the multiple-instance template ('Template:Ingredient') that are nested in a main template ('Template:Recipe'), and send the retrieved data to a different template ('Template:Format ingredient'), with different parameter names. The 'lazy' (deferred) mode is available if you have also installed Extension:ParseRequest.

{{#tf-convert:
|page=My Recipe for Grilled Chipotle Tofu
|sourcetemplate=Recipe[Ingredients].Ingredient
|targettemplate=Format ingredient
|data=Name=1,Description=2
|mode=lazy
}}

See also

Category:AdminLinks extensions Category:All extensions Category:Extensions in GitHub version control Category:Extensions not in ExtensionJson Category:Extensions with manual MediaWiki version Category:Extensions without a compatibility policy Category:Extensions without an image Category:GPL licensed extensions Category:InternalParseBeforeLinks extensions Category:ParserFirstCallInit extensions Category:Parser function extensions Category:RevisionFromEditComplete extensions Category:Stable extensions