(Created page with "<nowiki>Insert non-formatted text here</nowiki>{{Help:Header}} The '''UsingData''' extension adds parser functions which allow pages to specify and query "data" using template-l...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
− | + | {{Help:Header}} |
|
The '''UsingData''' extension adds parser functions which allow pages to specify and query "data" using template-like syntax, without affecting normal content transclusion. |
The '''UsingData''' extension adds parser functions which allow pages to specify and query "data" using template-like syntax, without affecting normal content transclusion. |
Revision as of 16:48, 13 February 2011
Help:Header
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|...}}
- 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.
- ...
- 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|Template|DefaultValue|...}}
- Page
- Page to use data from (article title, assumed to be in the Main namespace by default).
- 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 on Page, and this value is specified, #using will return this instead of parsing Template.
- Note: Prior to 1.1.2, this is specifies an alternate template instead of an alternate value.
- ...
- Optional - Any additional named arguments to pass to Template, overriding any data from Page.
{{#usingarg:Page|Arg|DefaultValue}}
- Page
- Page to use data from (article title, assumed to be in the Main namespace by default).
- Arg
- Data key to query; the associated value on Page is returned if defined.
- DefaultValue
- Optional - If Page does not define Arg, this value will be returned instead (an empty string by default).
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-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}}