This is an archive copy of wikilivres.ca as of 18 February 2017 (from the WikiTeam dump). The original site is closed.
Template:Anchor/documentation
Jump to navigation
Jump to search
Template:Template doc page Template:TOCright
Usage
{{Anchor}} or its plural alias {{Anchors}} will insert one or more HTML anchors in a page at the location of its invocation, enabling direct #Links to this location.
- Code
Before{{Anchors|Foo|Bar & Baz|Three}}After- Gives
- BeforeTemplate:AnchorsAfter
Notes
- The template will handle up to 10 anchor names, but could very easily be extended to do twice or more. If you accidentally use more than 10 anchors, the template will output an error message in a yellow box to let you know about it instead of silently ignoring your extra anchors.
- When used to add anchors to a paragraph of prose, it is preferable to put the template at the very start of the paragraph (stuck to the first word, without space) so as to ensure that incoming #Links will result in the full paragraph be displayed on the reader's screen.
- You can add anchors aliases to a heading by using the syntax
==Heading title {{Anchors|Foo|Bar & Baz}}==
which results in "#Foo" and "#Bar & Baz" being alias targets of "#Heading title". This syntax doesn't alter the regular heading, which remains as functional as if the template wasn't inserted (i.e. still appears in the page's TOC, and section editing works as usual). The method is superior in that you can always see the aliases when editing this section only, and they work exactly like the heading's regular anchor. (This is not the case when the anchors are added one line above or below the heading. And adding anchors after the heading doesn't work.)
- Though aliases {{Anchor}} and {{Anchors}} will work interchangeably, it is preferable to use the singular alias for a single anchor, and the plural alias for multiple anchors. This will allow Special:Whatlinkshere/Template:Anchors to track usage of multiple anchors, and could help detecting and converting old-style
{{Anchor|Foo}}{{Anchor|Bar}}to{{Anchors|Foo|Bar}}.
Anchor names
- Anchor names shouldn't include characters "#" (hash), "|" (pipe) or "=" (equal). On the other hand, special characters such as " " (space), "," (comma), "&" (ampersand), etc. can be used directly both in anchors and links, because Wikipedia will process them automatically into an URL-acceptable format.
- Anchor names should preferably use "Sentence case" (as is the standard for headings and thus their anchors) for naming each anchor; that is, capitalize the first letter of the first word and any proper nouns, but leave the rest lowercase. Examples: "The title of my anchor", "The anchor from Ipanema", etc. Because some browsers have case-sensitive anchors, the anchor name used in the #Links should be absolutely identical to its target (rather than all-lowercase).
- Anchor names should be unique (with respect to all heading titles and additional anchors) on each the page; a duplicate anchor won't work since the #Links will always go to the first homonymous anchor on the page.
Linking
After that, you can have links sending directly to the line you marked:
- With
[[#Bar & Baz|link label]]when linking from the same page - With
[[Article name#Bar & Baz|link label]]when linking from another page
Technical
- The template is based on
<SPAN ID="anchor" /> - The final HTML page (as outputted by Wikipedia to the reader's browser) will have converted it to
<SPAN ID="anchor"></SPAN>instead. - The more backward-compatible
<A NAME="anchor" ID="anchor"></A>is used by Wikipedia's own headings but disabled for editors in the wikicode and thus not used here.