Manual:Hooks/ParserFetchTemplateData

From Linux Web Expert

ParserFetchTemplateData
<translate> Available from <tvar name=1><translate> version <tvar (Gerrit change 494817)</tvar></translate>
Fetches template data for an array of template titles
<translate> Define function:</translate>
public static function onParserFetchTemplateData( array $titles, array &$ret ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"ParserFetchTemplateData": "MediaWiki\\Extension\\MyExtension\\Hooks::onParserFetchTemplateData"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> includes/parser/Parsoid/Config/DataAccess.php
<translate> Function(s):</translate> fetchTemplateData
<translate> Interface:</translate> ParserFetchTemplateDataHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ParserFetchTemplateData extensions</tvar>.</translate>


Parameters

  • $titles: 1-dimensional array of strings, representing template titles
  • &$templateData: array map (contains key-value pairs) passed by reference, which can be modified by extensions to send their own template data

Use cases

Currently, TemplateData uses this extension. TemplateData adds each template title to the $templateData map, and will assign one of the following values:

  • If a title is invalid title or is an invalid redirect title, gives a null value
  • If a title doesn't exist, will assign it a 'missing' key assigned with true
  • If a title has invalid data from the database, or does not have a 'templatedata' property in the page_props table, assign it as: (object)[ "notemplatedata" => true ]

Notes