Template:Data: Difference between revisions
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly>{{{1| | <includeonly>{{#if:{{{1|}}}||{{error|Missing parameter '1' for Template:Data}}}}{{#ifexist:{{{1|}}}|{{:{{{1|}}}|format=#switch:{{{2|}}}|{{{3|}}}}}|{{error|Page '{{{1|}}}' does not exist}}}}</includeonly><noinclude> | ||
<templatedata> | <templatedata> | ||
Line 29: | Line 29: | ||
</templatedata> | </templatedata> | ||
This template is based on the [http://kol.coldfront.net/thekolwiki/index.php/Template:Data Template:Data] page. | This template is based on the [http://kol.coldfront.net/thekolwiki/index.php/Template:Data Template:Data] page in the KoL wiki. | ||
==What is a Data Page?== | ==What is a Data Page?== | ||
Suppose a page named "XYZ" contains the following wikitext: | Suppose a page named "XYZ" contains the following wikitext: | ||
< | <pre>{{{{{format|DefaultTemplate}}} | ||
|param1=abc | |param1=abc | ||
|foo=bar | |foo=bar | ||
Line 40: | Line 40: | ||
|empty_value= | |empty_value= | ||
|{{{1|}}} | |{{{1|}}} | ||
}}</ | }}</pre> | ||
Any page that contains code like this is a | Any page that contains code like this is a ''data page''. A data page cannot render itself, but instead feeds its parameters to a rendering template ("DefaultTemplate" in this example) which is responsible for rendering the page. | ||
(Note: The markup above must be wrapped in a <code><onlyinclude></onlyinclude></code> tag.) | |||
The [[Template:Data]] template can extract individual fields from a data page, like this: | The [[Template:Data]] template can extract individual fields from a data page, like this: |
Latest revision as of 12:02, 20 December 2020
Utility template that extracts a field from a data page.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Page name | 1 | Name of the data page to extract the data from.
| Page name | required |
Field name | 2 | Name of the field to extract from the source page
| Line | required |
Default value | 3 | Default value if the page does not contain the given field, or the field is empty
| String | optional |
This template is based on the Template:Data page in the KoL wiki.
What is a Data Page?
Suppose a page named "XYZ" contains the following wikitext:
{{{{{format|DefaultTemplate}}} |param1=abc |foo=bar |some.property=some value |empty_value= |{{{1|}}} }}
Any page that contains code like this is a data page. A data page cannot render itself, but instead feeds its parameters to a rendering template ("DefaultTemplate" in this example) which is responsible for rendering the page.
(Note: The markup above must be wrapped in a <onlyinclude></onlyinclude>
tag.)
The Template:Data template can extract individual fields from a data page, like this:
Wiki markup | Result |
---|---|
{{data|XYZ|param1}} |
abc |
{{data|XYZ|foo}} |
bar |
{{data|XYZ|some.property}} |
some value |
{{data|XYZ|empty_value}} |
|
{{data|XYZ|empty_value|default value}} |
default value |
{{data|XYZ|value that does not exist|default value}} |
default value |