Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!

Help:UsingData

From Wowpedia
Jump to: navigation, search
HELP CONTENTS · Getting Started · New to Wowpedia · Editing Wowpedia · The Wowpedia Community · Additional Help
See http://meta.wikimedia.org/ Meta-Wiki HelpIntro for basic MediaWiki usage!

The UsingData extension adds parser functions which allow pages to specify and query "data" using template-like syntax, without affecting normal content transclusion.

In the context of this extension, "data" consists of key-value pairs, similar to named template arguments, which can be associated with a page by using the #data parser function directly on that page, and accessed by using the #using and #usingarg parser functions elsewhere on the wiki.

Specifying data

To specify the list of key-value pairs associated with a page, use the #data parser function directly on the desired page. The data function outputs the result of passing the specified arguments to the specified template.

{{#data:Template#Fragment|...}}

Template 
Name of the template (article title, assumed to be in the Template namespace by default) to pass the specified arguments to to produce returned output. If you do not want to produce visible output (and only wish to specify the key-value pairs), Blank is an appropriate choice.
Fragment 
An optional string specifying a namespace for the key-value pairs to be added to; the data will only be available if retrieved with the same fragment.
... 
Any number of named template arguments (e.g. "|foo=bar|baz=qux") to associate with the page.

To work correctly, the #data function must be placed directly on the associated page (as it acts only as a template call when transcluded), and not be wrapped in <includeonly> tags.

Querying data

To use the data specified on some page, you can use the #using and #usingarg parser functions.

{{#using:Page#Fragment|Template|DefaultValue|...}}

Page 
Page to use data from (article title, assumed to be in the Main namespace by default).
Fragment 
An optional string specifying which namespace to retrieve data from. Only data set using {{#data:...#Fragment| will be retrieved.
Template 
Template to parse with the data from Page passed as arguments (article title, assumed to be in the Template namespace by default).
DefaultValue 
Optional - If there's no #data (with corresponding Fragment) on Page, and this value is specified, #using will return this instead of parsing Template.
... 
Optional - Any additional named arguments to pass to Template, overriding any data from Page.

{{#usingarg:Page#Fragment|Arg|DefaultValue}}

Page 
Page to use data from (article title, assumed to be in the Main namespace by default).
Fragment 
An optional string specifying which namespace to retrieve data from. Only data set using {{#data:...#Fragment| will be retrieved.
Arg 
Data key to query; the associated value on Page is returned if defined.
DefaultValue 
Optional - If Page does not define Arg (with corresponding Fragment), this value will be returned instead (an empty string by default).


Additionally, the <using page="Page#Fragment" default="DefaultValue">TemplateCode</using> tag may be used to provide template code in-line:

Page 
Page to use data from (article title, assumed to be in the Main namespace by default).
Fragment 
An optional string specifying which namespace to retrieve data from. Only data set using {{#data:...#Fragment| will be retrieved.
DefaultValue 
Optional - If there is no #data (with specified Fragment) on Page, and this value is specified, the tag will output this value expanded in the current context.
TemplateCode
The tag contents will be expanded using the key/value pairs from Page (with specified Fragment) as template arguments.

Additional arguments

When invoked through the #data/#using functions, templates are passed these additional arguments, which override any others with the same name:

data-source 
Canonical page title of the page passed data is defined on (or queried from).
data-fragment 
Fragment value the current data is defined for or queried from.
data-source-fragment
Canonical page title of the page passed data is defined on (or queried from), including the fragment if specified. Available in #using contexts only.
data-sourcee 
data-source, escaped for comparison with {{FULLPAGENAME}}.
data-found 
An empty string if the #using call could not locate any #data tags on the source page; a non-empty string otherwise.

Examples

Test Item (example) 
Use #data to define item-related data directly on the item page; this doubles as a call to a template that generates the item tooltip for the page.
{{#data:Tooltip
|name=Test
|quality=Epic
}}
Template:Link/format 
A template generates a formatted link based on passed (named) arguments, matching those used in the #data call above.
{{loot|{{{quality}}}|{{{data-source}}}|{{{name}}}}}
Template:Link 
Hides #using: syntax from users, instructs the parser to parse Template:Link/format with the data specified on Test Item (example), and overrides the |name argument with the provided caption.
{{#using:{{{1}}}|Link/format|name={{{2|}}}}}
Another article 
Uses the wrapper template to generate a formatted, captioned link.
{{Link|Test Item (example)|Caption}}