Extension:TemplateFunc
Release status: stableCategory:Stable extensions |
|
|---|---|
| Implementation | Parser functionCategory: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 |
|
|
| Licence | GNU General Public License 3.0 or later |
| Download | GitHub:
Category:Extensions in GitHub version controlNote: |
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
TemplateFuncin yourextensions/folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'TemplateFunc' );
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.
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
}}
