Editing
Template:Anchor/doc
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Examples == # <code style="color:darkgreen;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}|Foo<nowiki>}}</nowiki></code> <br /> could be linked to with <code><nowiki>[[#Foo|...]]</nowiki></code> from ''within the same article'' (let's call this article "Qux"), <br /> or it could be linked to with {{nowrap|<code><nowiki>[[</nowiki>Qux#Foo<nowiki>|...]]</nowiki></code>}} from ''other'' articles and from redirects (where the ellipsis after the word "Foo" here means the words chosen to represent that link in the Wikipedia article, which, of course, could be anything). # Anchors can be more suitable for inter-article linking than section titles are because they are more stable. For example a section title {{nowrap|1=<code>== Foo ==</code>}} within a Wikipedia article titled <code>Qux</code>: <br /> {{nowrap|1=<code style="color:dimgray;"><nowiki>==</nowiki><span>{{sp}}</span><code style="color:darkgreen;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}<nowiki>|Foo}}</nowiki></code><span>{{sp}}</span>Foo <nowiki>==</nowiki></code>}} <br /> Here, links via {{nowrap|1=<code><nowiki>[[</nowiki>Qux#Foo<nowiki>]]</nowiki></code>}} would remain valid even if the section were renamed {{nowrap|1=<code><nowiki>== {{anchor#Foo}} On foo and its many friends ==</nowiki></code>}} (note that the anchor is placed ''before'' the section name; otherwise browsers may hide the section title from view). # However, within section titles, it may be preferable to simply use direct HTML, like this: <br /> {{nowrap|1=<code style="color:dimgray;"><nowiki>==</nowiki><span>{{sp}}</span><code style="color:darkgreen;"><nowiki><span id="Foo"></span></nowiki></code><span>{{sp}}</span>Foo <nowiki>==</nowiki></code>}}<br />This provides the same stable, linkable anchor as the {{tlx|anchor}} template, but also provides some additional visual advantages. For details, see [[#Limitations|§ Limitations]] below. # The template can be used to create multiple anchors with a single call. For example, <br /> {{nowrap|1=<code style="color:darkgreen;"><nowiki>{{</nowiki>{{lc:{{BASEPAGENAME}}}}<nowiki>|Foo|Bar|baz}}</nowiki></code>}} <br /> will create three anchors that can then be linked to with <code><nowiki>[[#Foo]]</nowiki></code>, <code><nowiki>[[#Bar]]</nowiki></code> and <code><nowiki>[[#baz]]</nowiki></code>. # Here is a more literal example: say you wrote an article about a recently discovered Proto-Indo-European language called "Yish Yash". The title of your article would probably also be "Yish Yash" or perhaps "Yish Yash (language)" (if there were already an article titled "Yish Yash" that covered the culture generally). Let's say you chose "Yish Yash (language)". Now let's say that within your article you wished to have a section titled "The placement of the tongue when producing Yish Yash vowel sounds". You would create a section heading that looked like this:<br />{{nowrap|1=<code><nowiki>== The placement of the tongue when producing Yish Yash vowel sounds == </nowiki></code>}}<br />Let's say that you then finished up writing and saved the new article. Now, say you came across another article on Wikipedia titled "Proto-Indo-European vowels" which happened to have a section on the unique tongue placement used in Yish Yash. You decided it might be useful here for readers to be able to quickly access the section of your article on Yish Yash tongue placement when forming vowels; however, you don't want to send them to the beginning of the whole article on the Yish Yash language (you wanted to target them more specifically). So you create a link in the Proto-Indo European vowel article to the ''section'' within ''your'' article on the placement of the tongue in Yish Yash: you might do so by editing the text of the Proto-Indo-European vowel article and adding something like this to a relevant place within it:<br />{{nowrap|1=<code><nowiki>[[Yish Yash (language)#The placement of the tongue when producing Yish Yash vowel sounds|Yish Yash tongue placement]] is particularly interesting.</nowiki></code>}}<br />That is some ''really'' long code, but it would create a direct link to the relevant section of the new Yish Yash language article and would look like this in the article on Proto-Indo-European vowels:<br /> "...<span style="color:blue;">Yish Yash tongue placement</span> is particularly interesting..." <br /> Now let's say another editor came along and wished to change the heading of this section of your article for some legitimate reason—perhaps to "Yish Yash vowels and the tongue". He or she could do so by editing your article and making the section heading look like this:<br />{{nowrap|1=<code><nowiki>== Yish Yash vowels and the tongue ==</nowiki></code>}}<br />Unbeknownst to that editor, this would mean the link in the article on Proto-Indo-European vowels that you created earlier would now go by default to the top of the Yish Yash article instead of your carefully-chosen subsection! However, if an ''anchor'' were placed within the section heading of the Yish Yash article either when you created it or when the other editor came along and changed it—perhaps something like this:<br />{{nowrap|1= <code><nowiki>== {{anchor|Tongue}} The placement of the tongue when producing Yish Yash vowel sounds ==</nowiki></code>}}<br />or like this:<br />{{nowrap|1=<code><nowiki>== {{anchor|Tongue}} Yish Yash vowel/ tongue interaction ==</nowiki></code>}} and the text of the article on Proto-Indo-European vowels had been changed by you to something like this:<br />{{nowrap|1=<code><nowiki>[[Yish Yash (language)#Tongue|Yish Yash tongue placement]] is particularly interesting.</nowiki></code>}}<br /> then the link from the Proto-Indo-European article would continue to point to the relevant ''section'' of the Yish Yash article, even if the wording of the section heading there had changed completely and without the reader having to sort it out for themselves. The use of anchors can make for a cleaner, more efficient Wikipedia reading experience where section headings are changed... Which they not infrequently are. === Limitations === {|class="wikitable" style="float:right" !Character ![[Character entity reference|Code]] !Template !Meaning |- |" |<code>&quot;</code> <br /><code>&#34;</code> |{{N/a}} |(double) [[quotation mark]] |- |# |<code>&#35;</code> |{{N/a}} |[[Number sign|hash]] |- || |<code>&#124;</code> |{{tl|!}} |[[Vertical bar|pipe]] |- |= |<code>&#61;</code> |{{tl|{{=}}}} |[[Equals sign|equals]] |} * 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 "&#" codes shown for them here. Or, the pipe symbol and equals sign can be worked around with {{tl|!}} and {{tl|{{=}}}}, respectively. Markup code such as {{tag|sup|o}} and {{tag|sub|o}} (superscript and subscript) cannot be used. Most other characters, including white space and punctuation, are not a problem. * Anchor names should be unique on a page, and should not duplicate any heading titles. Duplicate anchors will not work as expected since the <code><nowiki>#location</nowiki></code> links go to the first anchor with that name. Duplicate anchors result in invalid HTML; you can check for duplicate anchors by running the page through the [[W3C Markup Validation Service]]. * 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 {{nowrap|1="<code><nowiki>/* {{anchor|Issues}}Limitations */ New issue</nowiki></code>"}}. Also, when the section is saved, browsers may not return to the section. Consider using <code><nowiki><span id="..."></span></nowiki></code> directly, rather than using the anchor template, when in a section title. * Anchor links are case sensitive in some browsers, so treat all anchor links as case sensitive. === Use in tables === Anchors may be used within tables, subject to certain restrictions. The {{tlx|anchor}} template may be used in the caption and cells of a table, but not those portions of a table that are outside the caption and cells. It is used on the table's caption thus:<syntaxhighlight lang=text>|+ {{anchor|FooX}} A table caption</syntaxhighlight> and the following forms of cell are valid:<syntaxhighlight lang=text>!{{anchor|Foo1}} A header cell !style="background:white;" |{{anchor|Foo2}} A header cell with styling |{{anchor|Foo3}} A data cell |rowspan=2 |{{anchor|Foo4}} A data cell spanning two rows</syntaxhighlight> You need to ensure that the {{tlx|anchor}} is not in that portion of the markup intended for the classes, styles etc. Thus, {{tlx|anchor}} cannot be placed anywhere on lines that begin with <code><nowiki>{|</nowiki></code> (start of table) or <code><nowiki>|-</nowiki></code> (new row), and the following forms of cell are not valid:<syntaxhighlight lang=text>!{{anchor|Foo1}} |A header cell !style="background:white;" {{anchor|Foo2}} |A header cell with styling |{{anchor|Foo3}} |A data cell |rowspan=2 {{anchor|Foo4}} |A data cell spanning two rows</syntaxhighlight> If it is necessary for an anchor to be in any of these positions, a different technique is used—the <code>id=</code> attribute. This is placed in that portion of the markup where the classes, styles etc. may be used, as follows:<syntaxhighlight lang=text>{| id=FooX class=wikitable |- id=FooY !id=Foo1 |A header cell !style="background:white;" id=Foo2 |A header cell with styling |id=Foo3 |A data cell |rowspan=2 id=Foo4 |A data cell spanning two rows</syntaxhighlight> The <code>id=</code> attribute may appear before, between or after any other attributes that may be present, but only one <code>id=</code> attribute may be used in each of these areas. === TemplateData === {{TemplateDataHeader}} <templatedata>{ "description": "The template {{anchor}} inserts one or more HTML anchors in a page. Those locations can then be linked to using [[#location|...]] syntax. The parameters labels shown here (e.g., 'First anchor', '1', and the rest) are provided for convenience; no parameter label is required in the template itself, so you may create an anchor within an article by typing {{anchor|go here}} or {{anchor|this is it}} rather than {{anchor|First anchor=go here}} or {{anchor|1=this is it}} (though both formats will work correctly). You may not use {{anchor}} all by itself, however, as this is like dropping a ship's anchor without tying a rope to it: it holds nothing in place, can't be found or used, and messes up the sea floor with garbage!", "params": { "1": { "label": "First anchor", "description": "First anchor value; Only the first anchor is required.", "type": "string", "required": true }, "2": { "label": "Second anchor", "description": "Second anchor.", "type": "string", "required": false }, "3": { "label": "Third anchor", "description": "Third anchor.", "type": "string", "required": false }, "4...": { "label": "4th, 5th... anchor", "description": "For additional anchors, just add additional anchors (the template isn't limited to three)", "type": "string", "required": false } }}</templatedata> === See also === * {{#ifeq:{{BASEPAGENAME}}|Visible anchor|{{tl|Anchor}}|{{tl|Visible anchor}}}} * {{tl|Anchored list}} * {{tl|Anchor comment}} * {{tl|Shortcut}} * [[WP:ANCHOR]] * [[WP:TARGET]] <includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox|| <!-- CATEGORIES HERE, AND INTERWIKIS TO WIKIDATA, THANKS --> [[Category:Templates with no visible output]] }}</includeonly>
Summary:
Please note that all contributions to Meta Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Meta Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Dark mode
Contributions
Create account
Log in
Namespaces
Template
Discussion
English
Views
Read
Edit
View history
More
Purge
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information
Get shortened URL