Template:Anchor/doc

From MozillaWiki
Jump to: navigation, search
Edit-copy green.svg
This is a documentation subpage for Template:Anchor.
It contains usage information, categories and other content that is not part of the original template page.

Usage

{{anchor}} inserts one or more HTML fragment identifiers, commonly known as anchor names, at the location where you put the template in a page. It does so by using the id attribute within <span> tags:

  • <span id="Anchor name"></span>

These locations can then be linked to using the in-page wikilink syntax [[#Anchor name|…]].

Example anchors

Anchors are "invisible" on the page, i.e. they can only be seen as code inside the source code. You can click the links below to see how anchors work. They will take you to the Examples section, and the corresponding example anchor.

  • Link 1 goes to a location ("Target 1") with only 1 anchor name attached to it.
  • Link 2, link 3, and link 4 go to a location ("Target 2") with 3 anchor names attached to it.
  • Link 5 goes to a mock section title ("Section title A" in the Examples table), which has been given an anchor using {{anchor}}.
  • Link 6 goes to a mock section title ("Section title B" in the Examples table), which has been given an anchor using HTML code.

Parameters

There are 10 parameters, all unnamed, of which 1 is required and the remaining 9 are optional.

Syntax

The template's syntax is

  • {{anchor|anchor 1 |anchor 2 |anchor 3 |…|anchor 10 }}

Required parameter

1

Anchor name

The name of the (first) anchor.

Notes
  • There are some limitations to anchor names, e.g. concerning usage and syntax. See the section Limitations, below.
  • If no anchor name is specified, the template will show an error message.
Usage
  • {{anchor|1}}

Optional parameters

2–10

Additional anchor names

If you want, you can specify up to nine additional anchor names in the template (i.e. a maximum number of 10 anchor names).

Notes
  • There are some limitations to anchor names, e.g. concerning usage and syntax. See the section Limitations, below.
  • If 11 or more anchor names are specified, the template will show an error message.
Usage
  • {{anchor|1|2|3|…|10}}

Limitations

Character Code Template Meaning
"
&quot;
&#34;
N/A
Quotation mark
#
&#35;
N/A
Number sign
&#124;
{{!}}
Vertical bar
=
&#61;
{{=}}
Equals sign
Troublesome characters
  • Anchor names that contain any character shown in the table to the right will not work as expected. However, any of these characters can be replaced with the "&#…" codes shown for them here. The pipe symbol and equals sign can optionally be worked around with {{!}} and {{=}}, respectively. Most other characters, including white space and punctuation, are not a problem.
Markup code
  • Markup code such as <sup> and <sub> (superscript and subscript) cannot be used.
Duplicate anchor names
  • All wiki article and section titles created by using wiki markup (==, ===, etc.) automatically produce anchors with the same name as the titles themselfs. Duplicate anchors will not work as expected since the #location links go to the first anchor with that name. Because of this, anchor names should be unique on a page. Make sure your anchors don't duplicate any titles or other anchors, including ones written in direct HTML.
Section titles
  • If the template is added to a section title then the code will appear in the edit summary window when that section is edited, as in "/* {{anchor|Issues}}Limitations */ New issue". Also, when the section is saved, browsers may not return to the section. Consider to instead use the HTML code for anchors, <span id="…"></span>, rather than using the anchor template, when in a section title.
Treat as case-sensitive
  • Anchor links are case-sensitive in some browsers, so treat all anchor links as case-sensitive.

Examples

Correct use

The links to the targets in the table can be found under Usage > Example anchors, above.

Case What you write What you see Comments
Basic use Example1}} Target 1 Target 1 Can be linked to with [[#Example1|…]] from within the same article, or with [[Article name#Example1|…]] from other articles and from redirects.
Multiple anchors Example2|Example3|Example4}} Target 2 Target 2 Creates three anchors for the same target location that then can be linked to with [[#Example2|…]], [[#Example3|…]], or [[#Example4|…]], respectively.
Section title
(template)
Example5}} Section title A ==  Section title A Anchors can be more suitable for inter-article linking than section titles are. In this case, links in the format [[Article name#Example5]] would remain valid even if the section itself was renamed. (Note that the anchor is placed before the section name; otherwise browsers may hide the section title from view.)
Section title
(HTML)
== <span id="Example6"></span> Section title B ==  Section title B As noted under Limitations above, it may be preferable to use direct HTML rather than the template within section titles.
Incorrect use
Case What you write What you see
> 10 anchors 1|2|3|4|5|6|7|8|9|10|11}} Error in {{anchor}}: too many anchors, maximum is 10.
No parameter {{anchor}} Error in {{anchor}}: no anchor name has been specified.

External links