Template:Tag and Template:Tag/sandbox: Difference between pages
Minh Nguyen (talk | contribs) m (Protected "Template:Tag": High traffic page: Basically every page on the wiki uses this template a bazillion times; suggested at https://osmus.slack.com/archives/C03D01MP6RX/p1711148310189069?thread_ts=1711062976.797819&cid=C03D01MP6RX ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) |
Minh Nguyen (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<tt dir="ltr" class="mw-content-ltr" style="background:#EEF;font-size:1em;line-height:1.6">< |
<tt dir="ltr" class="mw-content-ltr" style="background:#EEF;font-size:1em;line-height:1.6">{{#invoke:tag|tag<noinclude>|removed|:=flag:type|national|;=regional|;;=municipal|;;;=organisation</noinclude>}}</tt><noinclude> |
||
{{Documentation}} |
|||
Where the result of a template or ParserFunction expansion starts with a star, colon or semicolon, an automatic newline is added: |
|||
</noinclude> |
|||
https://meta.wikimedia.org/wiki/Help:Newlines_and_spaces#Automatic_newline |
|||
This is particularly unfortunate, as this is not what we want to do in several cases, and a newline will break what we're doing. The answer is to put something in so that the expanded text *doesn't* start with one of those characters, but which doesn't actually contribute to the final output: we choose "<nowiki/>" for that purpose. |
|||
Which style of key linking do we have? |
|||
-->{{#if:{{{:|}}} |
|||
|<!--Type 1: Each key part is separately linked. |
|||
-->[[{{TagPagename|lang={{{kl|}}}|1={{{1<noinclude>|name</noinclude>}}}}}|{{{1<noinclude>|name</noinclude>}}}]]:<!-- |
|||
-->[[{{TagPagename|lang={{{kl:|}}}|1={{{:|}}}}}|{{{:|}}}]]<!-- |
|||
-->{{#if:{{{::|}}}|<nowiki/>:[[{{TagPagename|lang={{{kl::|}}}|1={{{::|}}}}}|{{{::|}}}]]}} |
|||
|<!--Type 2: Whole key is linked to main key page. |
|||
-->[[{{TagPagename|lang={{{kl|}}}|1={{{1<noinclude>|name</noinclude>}}}}}|{{{1<noinclude>|name</noinclude>}}}{{#if:{{{subkey|}}}|<nowiki/>:{{{subkey|}}}{{#if:{{{subkey2|}}}|<nowiki/>:{{{subkey2|}}}}}}}]] |
|||
}}</bdi>=<!--There's *always* an equals sign displayed.-->{{#if:{{{2|}}} |
|||
|<!--If there is a value provided, we use that and link it appropriately. |
|||
-->[[{{TagPagename|lang={{{vl|}}}|1={{#if: {{{::|}}}|{{{::}}}|{{#if:{{{:|}}}|{{{:|}}}|{{{1<noinclude>|name</noinclude>}}}}}}}|2={{{2|}}}}}<!-- |
|||
-->|<bdi>{{{2|}}}</bdi>]]<!-- |
|||
If there are separate values in addition to the first value listed, these are provided in the "subval" (alias ";") and "subval2 (alias ";;") parameters. |
|||
-->{{#if:{{{subval|}}}{{{;|}}}|<nowiki/>;[[{{TagPagename|lang={{{vl2|}}}|1={{#if:{{{::|}}}|{{{::|}}}|{{#if:{{{:|}}}|{{{:|}}}|{{{1<noinclude>|name</noinclude>}}}}}}}|2={{{subval|}}}{{{;|}}}}}|<bdi>{{{subval|}}}{{{;|}}}</bdi>]]}}<!-- |
|||
-->{{#if:{{{subval2|}}}{{{;;|}}}|<nowiki/>;[[{{TagPagename|lang={{{vl3|}}}|1={{#if:{{{::|}}}|{{{::|}}}|{{#if:{{{:|}}}|{{{:|}}}|{{{1<noinclude>|name</noinclude>}}}}}}}|2={{{subval2|}}}{{{;;|}}}}}|<bdi>{{{subval2|}}}{{{;;|}}}</bdi>]]}} |
|||
|<!--Where there is no value provided in the second numbered parameter, this is either a special link type, or simply just a key with no value, where we jsut put a star. First, do special handling of special link types for specific keys, using the optional third parameter (used for all values with external links).-->{{#switch:{{{1|}}} |
|||
|wikipedia={{#if:{{{3|}}}|[[w:{{#if:{{{subkey|}}}|{{{subkey|}}}:{{#if:{{{subkey2|}}}|{{{subkey2|}}}:}}}}{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|brand:wikipedia={{#if:{{{3|}}}|[[w:{{#if:{{{subkey|}}}|{{{subkey|}}}:{{#if:{{{subkey2|}}}|{{{subkey2|}}}:}}}}{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|operator:wikipedia={{#if:{{{3|}}}|[[w:{{#if:{{{subkey|}}}|{{{subkey|}}}:{{#if:{{{subkey2|}}}|{{{subkey2|}}}:}}}}{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|network:wikipedia={{#if:{{{3|}}}|[[w:{{#if:{{{subkey|}}}|{{{subkey|}}}:{{#if:{{{subkey2|}}}|{{{subkey2|}}}:}}}}{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|name:etymology:wikipedia={{#if:{{{3|}}}|[[w:{{#if:{{{subkey|}}}|{{{subkey|}}}:{{#if:{{{subkey2|}}}|{{{subkey2|}}}:}}}}{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|species:wikipedia={{#if:{{{3|}}}|[[w:{{#if:{{{subkey|}}}|{{{subkey|}}}:{{#if:{{{subkey2|}}}|{{{subkey2|}}}:}}}}{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|brand:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|operator:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|network:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|name:etymology:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|species:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|subject:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
|flag:wikidata={{#if:{{{3|}}}|[[d:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}} |
|||
<!--[[special:interwiki]]allows for d: or wikidata:; wikipedia allows for w:wikidata or w:d: (same for commons: below...w:c: or w:commons:)--> |
|||
|commons={{#if:{{{3|}}}|[[commons:{{{3|}}}|<bdi>{{{3|}}}</bdi>]]|<nowiki/>*}}<!-- |
|||
Quite a lot of the cases of these uses of this template currently don't match this implementation. More attention necessary (and more special links may be handled in this switch for specific tags that have authoritative description pages outside the OSM wiki: these may even be external URLs, notably for keys whose value is an external reference id, but these ids could be found by linking to Wikidata).--> |
|||
|url|website={{#if:{{{3|}}}|[{{{3|}}} <bdi style="white-space:normal"><!--Allow linebreaks in some long URLs (truncating the display value against width overflows is tricky)-->{{{3|}}}</bdi>]|<nowiki/>*}} |
|||
|#default={{#if:{{{3|}}}|<bdi>{{{3|}}}</bdi>|<nowiki/>*}} |
|||
}}}}</tt><noinclude>{{Documentation}}</noinclude> |
Latest revision as of 20:58, 27 November 2019
removed:flag:type=national;regional;municipal;organisation
Note to editors: Please don't categorize this template by editing it directly. Instead, place the category in its documentation page, in its "includeonly" section.
This template is used to represent an OpenStreetMap data key or key/value pair. Elements of the content are automatically linked to appropriate wiki pages.
This template is powered by Module:Tag.
Usage
The template can be used in a wide variety of ways. The simplest and most common usages are:
Description | Example wikitext | Result |
---|---|---|
A single key | {{Tag|highway}}
|
highway=* |
A specific key/value pair | {{Tag|highway|residential}}
|
highway=residential |
A key with a generic, literal value (not hyperlinked) | {{Tag|bridge||yes}}
|
bridge=yes |
A key with a description of value | {{Tag|ref||''ref number''}}
|
ref=ref number |
Multipart keys
Some key names can have multiple parts, often associated with key namespaces. One such example is keys associated with addresses: key addr:housenumber=* is used to specify a house number, addr:street=* is used to specify a name of a street, and so on. This template provides a choice of various approaches as to how the various parts of a multipart key are formatted: while the text itself remains the same, how the parts are linked differs.
- Single link to subkey page
- This approach treats the compound key as a single entity, and links to the wiki page describing that compound key.
{{Tag|building:fireproof}}
- produces a single link to the Key:building:fireproof wiki page, like so:
- This approach is most useful where a compound key is described on its own page, such as Key:building:fireproof or Key:addr:flats.
- This approach treats the compound key as a single entity, and links to the wiki page describing that compound key.
- Single link to main key page: The following wikitext:
- Multiple links to main key pages
{{Tag|oneway|:=bicycle}}
- produces separate links to each of the main wiki pages Key:oneway and Key:bicycle, like so:
- and:
{{Tag|cycleway|:=right|::=smoothness}}
- produces separate links to each of the main wiki pages Key:cycleway, Key:right and Key:smoothness, like so:
- This approach is most useful where each of the parts of the key is itself a main key, such as oneway:bicycle=*, where Key:oneway and Key:bicycle are both present.
Multiple values
Some keys can have multiple values specified, with each separated by a semicolon. Any number of additional values may be specified with this template, like so:
Example wikitext | Result |
---|---|
{{Tag|motor_vehicle|agricultural|;=forestry}}
|
motor_vehicle=agricultural;forestry |
{{Tag|access|agricultural|;=forestry|;;=destination}}
|
access=agricultural;forestry;destination |
To illustrate in the wiki the presence of different values and link to each values (including the use of {{TagValue}}).
Example wikitext | Result |
---|---|
{{Tag|wheelchair||({{TagValue|wheelchair|yes}}/{{TagValue|wheelchair|no}})}}
|
wheelchair=(yes/no) |
{{Tag|motor_vehicle||({{TagValue|motor_vehicle|agricultural}}/{{TagValue|motor_vehicle|forestry}})}}
|
motor_vehicle=(agricultural/forestry) |
{{Tag|access||({{TagValue|access|agricultural}}/{{TagValue|access|forestry}}/{{TagValue|access|destination}})}}
|
access=(agricultural/forestry/destination) |
Default target links to external sites for the values of specific keys
Some keys like wikipedia=*, wikidata=* or website=* may create external links, in that case their value in parameter 3 will be displayed (instead of just displaying an asterisk) along with their specific link according to their value; however when the value is the full URL of a website, unlike other tag values (that are generally short), that value is allowed to wrap when it is too long to fit on a line (this avoids making columns in feature tables to exceed a reasonable maximum width).
Only a few keys recognize this feature:
Example wikitext | Result |
---|---|
{{Tag|wikipedia||fr:Paris}}
|
wikipedia=fr:Paris |
{{Tag|wikipedia|subkey=fr||Paris}}
|
wikipedia:fr=Paris |
{{Tag|wikipedia|subkey=en||Paris}}
|
wikipedia:en=Paris |
{{Tag|wikidata||Q90}}
|
wikidata=Q90 |
{{Tag|operator:wikidata||Q90}}
|
operator:wikidata=Q90 |
{{Tag|website||http://www.paris.fr/}}
|
website=http://www.paris.fr/ |
For all other keys, the 3rd parameter is just displayed as is, without trying to convert them to new external links. This feature is also not used when the value is specified in the 2nd parameter (where it is used to generate internal links, if possible).
Linking to non-English pages
While the default action for the template is to link to the same language pages as the current one, it is possible to specify that a different language be used. The kl parameter is used to specify the language of the target of the key link, and the vl to specify the language of the value link. In each case, a standard language code is used.
Where a key contains multiple parts which are linked separately, the kl: parameter specifies the language for the second line, kl:: for the third link, and so on. Where a value contains multiple parts, the vl2 parameter specifies the language for the second link, vl3 for the third link, and so on.
The following examples illustrates this.
Example wikitext | Result |
---|---|
{{Tag|kl=de|highway|motorway}} | highway=motorway |
{{Tag|highway|vl=de|motorway}} | highway=motorway |
{{Tag|highway|motorway|kl=de|vl=de}} | highway=motorway |
{{Tag|cycleway|:=right|::=smoothness|excellent|kl=de|kl:=de|kl::=de}} | cycleway:right:smoothness=excellent |
TemplateData
Displays key or key=value pair automatically linked to appropriate wiki pages
Parameter | Description | Type | Status | |
---|---|---|---|---|
Key | 1 | Main key of the tag (the part before =)
| Line | required |
Value | 2 | A documented value of the key (the part after =)
| Line | suggested |
Freeform value or description | 3 | A description of the value which should not be linked as a value would be; second parameter should be undeclared for this to work. | Line | optional |
Key page language | kl | Language code of the key description page
| Line | optional |
Value page language | vl | Language code of the value description page
| Line | optional |
Subkey | subkey subkey1 | Key part described on the same page as the main key | Line | optional |
Subkey 2 | subkey2 | Second key part described on the same page as the main key | Line | optional |
Subkey 3 | subkey3 | Third key part described on the same page as the main key | Line | optional |
Subkey 4 | subkey4 | Fourth key part described on the same page as the main key | Line | optional |
Key component 2 | : | Second key part described on a separate page | Line | optional |
Key component 2 page language | kl: | Language code of the second key part description page
| Line | optional |
Key component 3 | :: | Third key part described on a separate page | Line | optional |
Key component 3 page language | kl:: | Language code of the third key part description page
| Line | optional |
Key component 4 | ::: | Fourth key part described on a separate page | Line | optional |
Key component 4 page language | kl::: | Language code of the fourth key part description page
| Line | optional |
Key component 5 | :::: | Fifth key part described on a separate page | Line | optional |
Key component 5 page language | kl:::: | Language code of the fifth key part description page
| Line | optional |
Value 2 | ; subval | Second documented value | Line | optional |
Value 2 page language | vl2 | Language code of the second value description page
| Line | optional |
Value 3 | ;; subval2 | Third documented value | Line | optional |
Value 3 page language | vl3 | Language code of the third value description page
| Line | optional |
Value 4 | ;;; subval3 | Fourth documented value | Line | optional |
Value 4 page language | vl4 | Language code of the fourth value description page
| Line | optional |
Value 5 | ;;;; subval4 | Fifth documented value | Line | optional |
Value 5 page language | vl5 | Language code of the fifth value description page
| Line | optional |
Language | lang | Language code of all the link targets
| Line | optional |
Disable categorization | nocat | Assigning any value disables the template's category linking behavior
| Boolean | optional |
See also
- {{TagKey}} – showing key only
- {{TagValue}} – for showing only the value
- {{Value}} – mark with light blue background and after font, looks similar like code
- {{LL}} – full page name of a specified page translated into the language used in the page currently viewed, similar to this template but for all pages
- {{Role}} – mark with light blue background and after font, looks similar like code
- {{Prefix}} – for showing a prefix
- {{Suffix}} – for showing a suffix