Difference between revisions of "Template:Anchor/doc"
From Help Wiki
(One intermediate revision by the same user not shown) | |||
Line 3: | Line 3: | ||
YOU CAN EDIT THE TEMPLATE DOCUMENTATION BELOW THIS COMMENT | YOU CAN EDIT THE TEMPLATE DOCUMENTATION BELOW THIS COMMENT | ||
--> | --> | ||
− | + | ||
==Usage== | ==Usage== | ||
− | '''<NOWIKI>{{</NOWIKI>{{BASEPAGENAME}}}}''' or its plural alias '''<NOWIKI>{{ | + | '''<NOWIKI>{{</NOWIKI>{{BASEPAGENAME}}}}''' or its plural alias '''<NOWIKI>{{Anchor}}</NOWIKI>''' will insert one or more HTML anchors in a page at the location of its invocation, enabling direct #Links to this location. |
; Code : <CODE><NOWIKI>Before{{Anchors|Foo|Bar & Baz|Three}}After</NOWIKI></CODE> | ; Code : <CODE><NOWIKI>Before{{Anchors|Foo|Bar & Baz|Three}}After</NOWIKI></CODE> | ||
Line 18: | Line 18: | ||
==Notes {{Anchor|Notes|Details}}== | ==Notes {{Anchor|Notes|Details}}== | ||
− | * 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: {{ | + | * 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: {{Anchor|1|2|3|4|5|6|7|8|9|10|11}} This will let you know about it instead of having your extra anchors be silently ignored. |
* 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. | * 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. | ||
Line 38: | Line 38: | ||
</PRE> | </PRE> | ||
− | * Though aliases <NOWIKI>{{</NOWIKI>{{BASEPAGENAME}}}} and <NOWIKI>{{ | + | * Though aliases <NOWIKI>{{</NOWIKI>{{BASEPAGENAME}}}} and <NOWIKI>{{Anchor}}</NOWIKI> 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:Anchor]] to track usage of multiple anchors, and could help detecting and converting old-style <CODE><NOWIKI>{{Anchor|Foo}}{{Anchor|Bar}}</NOWIKI></CODE> to <CODE><NOWIKI>{{Anchor|Foo|Bar}}</NOWIKI></CODE>. |
==Tips== | ==Tips== | ||
Line 52: | Line 52: | ||
: You would make it: | : You would make it: | ||
:: <CODE><NOWIKI>==Current division {{Anchor|Current division|Regions}}==</NOWIKI></CODE> | :: <CODE><NOWIKI>==Current division {{Anchor|Current division|Regions}}==</NOWIKI></CODE> | ||
− | |||
==Anchor names== | ==Anchor names== | ||
Line 58: | Line 57: | ||
* 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. | ||
− | * Anchor names should preferably be written in "Sentence case" (as is the | + | * 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. | * 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. |
Latest revision as of 16:32, 16 October 2007
Contents
Usage
{{Anchor/doc}} or its plural alias {{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{{Anchors|Foo|Bar & Baz|Three}}After
- Gives
- BeforeAfter
The template also works for adding aliases directly inside a heading.
- Code
-
==Notes {{Anchor|Notes|Details}}==
- Gives
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 like this: Template:Anchor: too much anchorsThis will let you know about it instead of having your extra anchors be silently ignored.
- 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 a syntax such as:
==Heading title {{Anchor|Foo|Bar & Baz}}==
- This results in "#Foo" and "#Bar & Baz" being alias targets of "#Heading title". This syntax doesn't alter the heading, which remains a regular heading as functional as if the template wasn't inserted (i.e. still appears in the page's TOC, and section editing works as usual). This method is advantageous in that you can always see the anchors list when editing this section only, and they work exactly like the heading's own 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 on the same line doesn't work.)
- 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, do not use here a vertical format such as:
==George Walker Bush {{Anchor | George W. Bush | George Bush | Bush | Dubya }}==
- Though aliases {{Anchor/doc}} and {{Anchor}} 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:Anchor to track usage of multiple anchors, and could help detecting and converting old-style
{{Anchor|Foo}}{{Anchor|Bar}}
to{{Anchor|Foo|Bar}}
.
Tips
- 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 a 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}}==
-
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 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
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.