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

Free texts and images.
Jump to navigation Jump to search
imported>Komusou
documented vertical format
imported>-jkb-
mNo edit summary
 
(64 intermediate revisions by 31 users not shown)
Line 1: Line 1:
{{Template doc page}}
===Description===
<!--
The template <nowiki>{{</nowiki>[[{{ns:Template}}:{{BASEPAGENAME}}|{{lc:{{BASEPAGENAME}}}}]]<nowiki>}}</nowiki> inserts one or more HTML anchors in a page. Those locations can then be linked to using <code><nowiki>[[#link|...]]</nowiki></code> syntax.
    PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE
    YOU CAN EDIT THE TEMPLATE DOCUMENTATION BELOW THIS COMMENT
-->
{{TOCright}}
==Usage==


'''<NOWIKI>{{</NOWIKI>{{BASEPAGENAME}}}}''' or its plural alias '''<NOWIKI>{{Anchors}}</NOWIKI>''' will insert one or more [[HTML element#Links and anchors|HTML anchor]]s in a page at the location of its invocation, enabling direct #Links to this location.
===Examples===


; Code  : <CODE><NOWIKI>Before{{Anchors|Foo|Bar & Baz|Three}}After</NOWIKI></CODE>
1. <code style="color:green;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}|foo<nowiki>}}</nowiki></code>
; Gives : Before{{Anchors|Foo|Bar & Baz|Three}}After
: could be linked to with <tt><nowiki>[[#foo|...]]</nowiki></tt> from within the same article,
: or it could be linked to with <tt><nowiki>[[</nowiki>''articlename''#foo|...<nowiki>]]</nowiki></tt> from other articles and from redirects.


==Notes==
2. Anchors can be more suitable for inter-article linking than section titles are. For example,
:<code style="color:gray;"><nowiki>==Section title==</nowiki></code>
:<code style="color:green;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}|foo<nowiki>}}</nowiki></code>
:Here, links via <tt><nowiki>[[</nowiki>''articlename''#foo<nowiki>]]</nowiki></tt> would remain valid even if the section were renamed.


* 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: {{Anchors|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.
3. The template can be used to create up to ten anchors with a single call. For example,
: <code style="color:green;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}|foo|bar|baz<nowiki>}}</nowiki></code>
:will create three anchors that can then be linked to with <tt><nowiki>[[#foo]]</nowiki></tt>, <tt><nowiki>[[#bar]]</nowiki></tt> and <tt><nowiki>[[#baz]]</nowiki></tt>.  
:Specifying more than 10 anchors will cause an error message to be displayed.


* 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.
===Limitations===
 
* Anchor names that contain the number sign &#35; (hash), vertical bar &#124 (pipe), equals sign &#61; (equal) will not work as expected. Most other characters, including white space and punctuation are not a problem.
* You can add anchors aliases to a heading by using a syntax such as:
* Anchors cannot be placed in the middle of other wiki syntax. For example, <code style="color:green;"><nowiki>==Heading{{</nowiki>{{lc:{{BASEPAGENAME}}}}|foo<nowiki>}}==</nowiki></code> will not work.
 
* The template can create a maximum of 10 anchors. Specifying more than 10 anchors will result in an error message.
<PRE>
* Care should be taken to ensure that names are on a single line: For example,
==Heading title {{Anchors|Foo|Bar & Baz}}==
:<code style="color:green;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}
</PRE>
:|humpty<br />dumpty<nowiki>}}</nowiki></code>  
 
:will probably not work as expected.
: 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.) For long aliases, you can also use the vertical format, such as:
* Anchor names should be unique (with respect to all heading titles and additional anchors) on each page; multiple anchors won't work as expected since the #links will always go to the first anchor with that name.
 
* Unlike section headings, anchors may not work on some (very old) browsers. This is because section headings are tagged with the more backward-compatible <code><nowiki><a name="heading" id="heading"></a></nowiki></code>. Such tagging cannot be achieved with templates.
<PRE>
==José Álvarez de Toledo y Gonzaga {{Anchors
| Don José Álvarez de Toledo y Gonzaga, 15th Duke of Medina-Sidonia
| Don José Álvarez de Toledo y Gonzaga, 13th Duke of Alba
| Don José Álvarez de Toledo y Gonzaga, 11th Marquis of Villafranca
}}==
</PRE>
 
: Or combinations of horizontal and vertical, such as:
 
<PRE>
==George Walker Bush {{Anchors
| George W. Bush | George Bush | Bush | Dubya
}}==
</PRE>
 
: Each format works the same as the others.
 
* Though aliases <NOWIKI>{{</NOWIKI>{{BASEPAGENAME}}}} and <NOWIKI>{{Anchors}}</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:Anchors]] 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>{{Anchors|Foo|Bar}}</NOWIKI></CODE>.
 
==Anchor names==
 
* Anchor names shouldn't include characters "#" (hash), "&#124;" (pipe) or "&#61;" (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 [[WP:MOSHEAD|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 <CODE><NOWIKI>[[#Bar & Baz|link label]]</NOWIKI></CODE> when linking from the same page
* With <CODE><NOWIKI>[[Article name#Bar & Baz|link label]]</NOWIKI></CODE> when linking from another page
 
==Technical==
 
* The template is based on <CODE><NOWIKI><SPAN ID="anchor" /></NOWIKI></CODE>
* The final HTML page (as outputted by Wikipedia to the reader's browser) will have converted it to <CODE><NOWIKI><SPAN ID="anchor"></SPAN></NOWIKI></CODE> instead.
* The more backward-compatible <CODE><NOWIKI><A NAME="anchor" ID="anchor"></A></NOWIKI></CODE> is used by Wikipedia's own headings but disabled for editors in the wikicode and thus not used here.
 
<includeonly>
 
<!-- PLEASE ADD CATEGORIES BELOW THIS LINE, THANKS. -->
 
[[Category:Function templates|{{PAGENAME}}]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
 
<!-- PLEASE ADD INTERWIKIS BELOW THIS LINE, THANKS. -->
 
[[fr:Modèle:Ancre]]
[[de:Vorlage:Anker]]
[[ru:Шаблон:Anchor]]
[[sl:Predloga:Sidro]]
 
</includeonly>

Latest revision as of 07:48, 23 April 2010

Description

The template {{anchor}} inserts one or more HTML anchors in a page. Those locations can then be linked to using [[#link|...]] syntax.

Examples

1. {{anchor|foo}}

could be linked to with [[#foo|...]] from within the same article,
or it could be linked to with [[articlename#foo|...]] from other articles and from redirects.

2. Anchors can be more suitable for inter-article linking than section titles are. For example,

==Section title==
{{anchor|foo}}
Here, links via [[articlename#foo]] would remain valid even if the section were renamed.

3. The template can be used to create up to ten anchors with a single call. For example,

{{anchor|foo|bar|baz}}
will create three anchors that can then be linked to with [[#foo]], [[#bar]] and [[#baz]].
Specifying more than 10 anchors will cause an error message to be displayed.

Limitations

  • Anchor names that contain the number sign # (hash), vertical bar &#124 (pipe), equals sign = (equal) will not work as expected. Most other characters, including white space and punctuation are not a problem.
  • Anchors cannot be placed in the middle of other wiki syntax. For example, ==Heading{{anchor|foo}}== will not work.
  • The template can create a maximum of 10 anchors. Specifying more than 10 anchors will result in an error message.
  • Care should be taken to ensure that names are on a single line: For example,
{{anchor
|humpty
dumpty}}
will probably not work as expected.
  • Anchor names should be unique (with respect to all heading titles and additional anchors) on each page; multiple anchors won't work as expected since the #links will always go to the first anchor with that name.
  • Unlike section headings, anchors may not work on some (very old) browsers. This is because section headings are tagged with the more backward-compatible <a name="heading" id="heading"></a>. Such tagging cannot be achieved with templates.