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
imported>-jkb-
mNo edit summary
 
(72 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
-->
==Usage==


This template inserts 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{{</NOWIKI>{{BASEPAGENAME}}<NOWIKI>|Foo|Bar & Baz|Three}}After</NOWIKI></CODE>
1. <code style="color:green;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}|foo<nowiki>}}</nowiki></code>
; Gives : Before{{{{BASEPAGENAME}}|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.


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.
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.


==Anchor names==
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.


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.
===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.
For simplicity and consistency, it is preferable to use "Sentence case" (as is the [[WP:MOSHEAD|standard for headings]] and thus their anchors) for naming each anchor; that is, an initial capital, then lowercase except for proper names. 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).
* 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.
==Linking==
* Care should be taken to ensure that names are on a single line: For example,
 
:<code style="color:green;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}
After that, you can have links sending directly to the line you marked:
:|humpty<br />dumpty<nowiki>}}</nowiki></code>  
 
:will probably not work as expected.
* With <CODE><NOWIKI>[[#Bar & Baz|link label]]</NOWIKI></CODE> when linking from the same page
* 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.
* With <CODE><NOWIKI>[[Article name#Bar & Baz|link label]]</NOWIKI></CODE> when linking from another page
* 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.
 
==Technical notes==
 
* 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.