Template:Anchor

From Gentoo Wiki
Jump to: navigation, search


[edit

Documentation

Note
This page is a template. It contains some standardized, often used text, which can be transcluded inside other pages.

As this template is widely used in our wiki, it may be protected in which case only staff members can change it. Use the discussion page to propose enhancements or fixes, or to voice your opinion.

This template inserts one or more (up to 10) HTML anchors into a page at the specified location. This location can then be linked to using the syntax:

  • [[#anchorname|link text]] (if linking from elsewhere on the same page), or
  • [[Pagetitle#anchorname|link text]] (if linking from a different page).

Parameters

Parameter name Required? Default value Description
Anonymous parameter 1 Yes (n/a) Anchor name.
Anonymous parameter 2 No (n/a) Optional second anchor name. (And so forth, up to 10 total.)

There can be up to 10 anchor names in a single call of this template. Specifying more than 10 anchors will result in an error message. If more anchors are desired, multiple template calls can be used. (But why would this ever be necessary??)

Since the anchor names will be used as "id" attributes in the rendered HTML, they should all be unique and should not conflict with any existing section headings, nor with the special reserved anchor name "top". Note that anchor links are case sensitive in most but not all browsers. (Because duplicate anchor names result in invalid HTML, they can be detected by running the page through the W3C Markup Validation Service.)

character code template meaning
" "
"
n/a (double) quotation mark
# # n/a number sign ("pound", "hash")
| {{!}} vertical bar ("pipe")
= = {{=}} equals sign

Anchor names that contain any character shown in the table on the right will not work as expected. However, any of these characters can be replaced with the corresponding "&#" codes shown. The pipe symbol and equals sign can also be replaced by {{!}} and {{=}}, respectively. Most other characters, including whitespace and punctuation, are not a problem.

Usage

{{anchor|…}}

Replace with one or more anchor names separated by vertical bars: |.

Since this template doesn't result in any visible output, no test cases are provided. However, some examples are shown below.

  1. {{anchor|foo}}
    • could be linked to with [[#foo|…]] from within the same article;
    • could be linked to with [[Article title#foo|…]] from other articles or from redirects.
  2. == {{anchor|foo}} Section title ==
    • could be used if something other than the current section heading is desired for incoming links of the form [[Article title#foo]];
    • however, it is preferable in such cases to use the following:
      == <span id="foo"></span> Section title ==
    • Do not do the following, as it will not work as expected:
      == Section title {{anchor|foo}} ==
  3. {{anchor|foo|bar|baz}}
    • will create three anchors that can then be linked to with [[#foo]], [[#bar]] and [[#baz]], respectively.
  4. {{anchor
    |humpty
    |dumpty}}
    • does not work as expected: unlike most templates, this one doesn't work when its parameters are split into separate lines.
Note
The above documentation is transcluded from Template:Anchor/doc. (edit | history)
Editors can experiment in this template's sandbox (create) and testcases (create) pages.
Please add categories and interwikis to the /doc subpage. (See the subpages of this template.)