Template:anchor/doc
Appearance
This template is used for inserting HTML anchors for easy linking from other pages.
Usage
[change]{{anchor}} will insert 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 also works for adding aliases directly inside a heading.
- Code
==Notes {{anchor|Notes|Details}}==
- Gives
- (see heading below)
Notes
[change]- 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 like this: Template:Anchor (or Anchors): too many anchors, maximum is ten This will let you know about it instead of having your extra anchors silently ignored.
- When used to add anchors to a specific definition, it is preferable to put the template at the very start of the definition (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 a syntax such as:
# {{anchor|medicine|medical}} {{medicine}} The act of causing swelling, itching, redness or pain to the body.
- This results in "#medicine" and "#medical" being targets of incoming #Links. This syntax doesn't result in any visible change. This method is advantageous in that you can always see the anchors list when editing this section only, and they work exactly like any ==Header== but without looking like one
- Even when you have many long aliases, you need to keep the heading and its embedded anchors on a single line (which may be very long and wrap), as its own single paragraph. Trying to use a vertical format for the template would give all the appearances of working, including section numbering, but actually trying to edit the section results in editing the next section instead, due to a bug. So, in headings, do not use here a vertical format such as:
# {{anchor | medicine }} {{medicine}} The act of causing swelling, itching, redness or pain to the body.
- 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.
Known bug
[change]- Currently, the anchor code is included in a section-edit summary. For instance, section-editing the "Notes" section of this page will pre-fill your edit summary with:
/* Notes {{anchor|Notes|Details}} */
- This is inconsequential for your edit, but can be inconvenient for your edit summary when there are many long anchor names. You can however edit it out to just:
/* Notes */
- This bug can't be helped in the template itself. It is hoped that a future version of the MediaWiki software will skip template calls in headings for section-edit summaries.
Tips
[change]- When you make a link from article A to article B#Heading, you can preemptively edit article B from
==Heading==
- To:
==Heading {{Anchor|Heading}}==
- (Note the singular "Anchor" here.) This will ensure the perennity of any link to #Heading, regardless of how the actual heading may be changed in the future. Since you can't expect other editors to mind your target anchors, this solution is more efficient and proactive than just adding an HTML comment "this heading is linked from article A" next to the heading.
- Similarly, when you add an anchor alias to a heading, you can preemptively add a copy-paste of the current heading's title along with your new anchor. For instance, for adding a "#Regions" anchor to this heading:
==Current division==
- You would make it:
==Current division {{anchor|Current division|Regions}}==
- (Note the plural "Anchors" here.) This too will ensure the perennity of both "#Current division" and "#Regions", regardless of other editors' future edits on the heading.
Anchor names
[change]- Due to technical limitations, anchor names can not 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 the software will process them automatically into a URL-compatible format.
- Anchor names should preferably be written in "Sentence case" (as is the standard for headings and thus their anchors); 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 a #Link 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 page; a duplicate anchor won't work since the #Links will always go to the first homonymous anchor on the page.
Linking
[change]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
[change]- 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.
TemplateData
[change]This is the TemplateData documentation for this template used by VisualEditor and other tools.
TemplateData for anchor
A template for adding HTML anchors to a page.
Parameter | Description | Type | Status | |
---|---|---|---|---|
First anchor | 1 | The first anchor. | String | required |
Second anchor | 2 | The second anchor. | String | optional |
Third anchor | 3 | The third anchor. | String | optional |
Forth anchor | 4 | The forth anchor. | String | optional |
Fifth anchor | 5 | The fifth anchor. | String | optional |
Sixth anchor | 6 | The sixth anchor. | String | optional |
Seventh anchor | 7 | The seventh anchor. | String | optional |
Eighth anchor | 8 | The eighth anchor. | String | optional |
Ninth anchor | 9 | The ninth anchor. | String | optional |
Tenth anchor | 10 | The tenth anchor. | String | optional |
Eleventh anchor | 11 | The eleventh anchor. Note that using this parameter will result in a warning that the number of anchors allowed has been exceeded. | String | optional |