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: Difference between revisions
imported>Komusou made {{Template doc page}} with copy of the template's doc (now semi-protected) and {{BASEPAGENAME}} for example calls and <includeonly> zone for cats/iws |
imported>Komusou tweaks, ==Anchor names== |
||
| Line 11: | Line 11: | ||
; Gives : Before{{{{BASEPAGENAME}}|Foo|Bar & Baz|Three}}After | ; Gives : Before{{{{BASEPAGENAME}}|Foo|Bar & Baz|Three}}After | ||
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 | 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. | ||
==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 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. | ||
For simplicity and consistency, it is preferable to use "Title case" (as is the [[WP:MOSHEAD|standard for headings]] and thus their anchors) for naming each anchor, that is an initial cap, and the all-lowercase except for proper names. Anchors such as "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). | |||
==Linking== | ==Linking== | ||
Revision as of 19:25, 3 October 2007
Usage
This template inserts one or more HTML anchors in a page at the location of its invocation, enabling direct #Links to this location.
- Code
Before{{Anchor|Foo|Bar & Baz|Three}}After- Gives
- BeforeAfter
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.
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.
For simplicity and consistency, it is preferable to use "Title case" (as is the standard for headings and thus their anchors) for naming each anchor, that is an initial cap, and the all-lowercase except for proper names. Anchors such as "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).
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 notes
- 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.