Jump to content

Template:W/doc

From Wikiquote

This template, {{W}}, produces interwiki links to Wikipedia using a standardized syntax that ensures that they behave as expected and produce the preferable wikipedia: prefix in the link's tooltip rather than the less helpful w: that appears when they are created manually using the ubiquitous shorthand interwiki link syntax.


Usage

[edit]

Only one parameter is required: the name of the target page on Wikipedia. In addition, different link text may be provided as an optional second unnamed/positional parameter, if desired. Interlanguage links are also supported by supplying the code for the desired target language variant of Wikipedia as a third such parameter (or as the value for an explicitly named |lang= parameter, if the second parameter is undefined). To wit:

{{W|Target page name|Link text|Language code}}
{{W|Target page name|lang=Language code}}
[edit]

The simplest way to use this template is with a single parameter for the target page name, which appears verbatim on the page when rendered, linked to the page with that name on English Wikipedia. For example, to create a link to the page about Albert Einstein's famous mass–energy equivalence formula, , insert this wikitext on the page:

{{W|Mass–energy equivalence}}Mass–energy equivalence

As with any link on a Mediawiki site, the first letter of the page name may be lowercased to suit mid-sentence usage without altering its behavior, as seen below.

{{W|mass–energy equivalence}}mass–energy equivalence
[edit]

Frequently, it is necessary to have text that differs from the name of the target page to suit the context, though editors are advised to use as much restraint as possible when doing so to avoid confusing or misleading readers. This template accommodates that need by providing a second unnamed/positional parameter which defines the link's text, separately from the name of the target page. Reusing the example from above, if when using this template a link was needed that led the same article but appeared instead as the text "Einstein's famous equation", it would take the form:

{{W|Mass–energy equivalence|Einstein's famous equation}}Einstein's famous equation
[edit]

To create an interlanguage link to Wikipedia, add a third parameter to the template with the desired language code as its value. Continuing to use the same example, to create a link to the page for mass-energy equivalence at Portuguese Wikipedia, the wikitext to use would be:

{{W|Equivalência massa–energia|lang=pt}}Equivalência massa–energia

To do so again, but creating a link whose text was the Portuguese translation of "Einstein's famous equation", the third parameter can be supplied unnamed (since this time the second parameter is defined, though the named syntax would also work just as well here), as in the case of:

{{W|Equivalência massa–energia|Equação famosa do Einstein|pt}}Equação famosa do Einstein

Tooltips and typestroke economy

[edit]

As mentioned earlier, a distinct advantage provided by this template is its use of the full interwiki link syntax which is reflected in the tooltip shown when one hovers their mouse over the link without the need to type the full name oneself. Compare the tooltips of the two links below.

[[w:Mass–energy equivalence|Mass–energy equivalence]] {{W|Mass–energy equivalence}}
Mass–energy equivalence Mass–energy equivalence

Not only does the template's tooltip present much greater clarity to the reader about the link's destination, especially for those who have no experience with Mediawiki as as editor, but it also eliminates the need to enter the page name again as the link text simply to prevent the interwiki prefix to be hidden! (To use the interwiki shorthand without link text produces this instead, the worst of both worlds: [[w:Mass–energy equivalence]]w:Mass–energy equivalence)

Known limitations

[edit]

If either the target page name or link text values happen to contain an equality symbol (=), that parameter must either be prepended with the numeric value in the parameter series followed by an equality symbol (either |1= or |2=) to convert it from the unnamed/positional format to the named syntax, or the equality symbol in the value must be replaced with one of:

  • = – the corresponding named HTML entity
  • = – the HTML entity in numeric decimal form
  • = – the numeric entity, this time in hexadecimal
  • {{=}} – the Mediawiki magic word that escapes the character

For example, to link to the Wikipedia article about Albert Einstein's famous equation using the equation itself () as the link text, either approach below will produce the desired result:

{{W|Mass–energy equivalence|2=E=mc²}}E=mc²
{{W|Mass–energy equivalence|E=mc²}}E=mc²

TemplateData

[edit]
This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. see a monthly parameter usage report for Template:W in articles.

TemplateData for W

Create an interwiki link to Wikipedia, with optional link text and language selection

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Target page name1

The name of the target page on Wikipedia

Example
Poetry
Linerequired
Link text2

The text to display on the page, if different than the target page name

Example
poem
Lineoptional
Wikipedia target language3 lang

The language variant of Wikipedia to link to, if not English

Default
en
Example
pt
Lineoptional

See also

[edit]