Template:Anchor: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>BenB4
(more docs)
meta>Komusou
(after testing in Template:Anchor/sandbox and Template:Anchor/testcases, version 2.0 : backward-compatible but will accept up to 10 {{Anchor|One|Two|Three}} anchors (plus new doc))
Line 1: Line 1:
<span id="{{{1|anchor}}}"/><noinclude>
<noinclude>{{#ifeq:{{SUBPAGENAME}}|sandbox|{{Template sandbox notice}}
This template manually adds an [[HTML element#Links and anchors|HTML anchor]] to a page at the location of its invocation. 
}}
</noinclude><!--
-->{{#if:{{{ 1|}}}|<SPAN ID="{{{ 1|}}}" /><!--
-->{{#if:{{{ 2|}}}|<SPAN ID="{{{ 2|}}}" /><!--
-->{{#if:{{{ 3|}}}|<SPAN ID="{{{ 3|}}}" /><!--
-->{{#if:{{{ 4|}}}|<SPAN ID="{{{ 4|}}}" /><!--
-->{{#if:{{{ 5|}}}|<SPAN ID="{{{ 5|}}}" /><!--
-->{{#if:{{{ 6|}}}|<SPAN ID="{{{ 6|}}}" /><!--
-->{{#if:{{{ 7|}}}|<SPAN ID="{{{ 7|}}}" /><!--
-->{{#if:{{{ 8|}}}|<SPAN ID="{{{ 8|}}}" /><!--
-->{{#if:{{{ 9|}}}|<SPAN ID="{{{ 9|}}}" /><!--
-->{{#if:{{{10|}}}|<SPAN ID="{{{10|}}}" /><!--
-->{{#if:{{{11|}}}
    |<DIV STYLE="background-color:yellow">[[Template:Anchor]]: too much anchors</DIV><!--
-->}}<!--
-->}} }} }} }} }} }} }} }} }} }}<noinclude>
<!--
    PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE
    YOU CAN EDIT THE TEMPLATE DOCUMENTATION BELOW THIS COMMENT
-->
==Usage==


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.
<pre>{{anchor|foo}}</pre>


With this you can link to <nowiki>[[Page#foo]]</nowiki> to have people following the link arrive at the anchor location.
; Code  : <CODE><NOWIKI>Before{{</NOWIKI>{{PAGENAME}}<NOWIKI>|Foo|Bar & Baz|Three}}After</NOWIKI></CODE>
; Gives : Before{{{{PAGENAME}}|Foo|Bar & Baz|Three}}After
 
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 a bold error message to let you know about it instead of silently ignoring your extra anchors.
 
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.
 
==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 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.
 
{{pp-semi-protected| small=yes | reason=No need for such template to be anon-editable. }}
 
<!-- PLEASE ADD CATEGORIES BELOW THIS LINE, THANKS. -->


[[Category:Function templates|{{PAGENAME}}]]
[[Category:Function templates|{{PAGENAME}}]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- PLEASE ADD INTERWIKIS BELOW THIS LINE, THANKS. -->


[[fr:Modèle:Ancre]]
[[de:Vorlage:Anker]]
[[de:Vorlage:Anker]]
<!--[[en:Template:Anchor]]-->
[[fr:Modèle:Ancre]]
[[ru:Шаблон:Anchor]]
[[ru:Шаблон:Anchor]]
[[sl:Predloga:Sidro]]
[[sl:Predloga:Sidro]]
</noinclude>
</noinclude>

Revision as of 19:00, 3 October 2007


Usage

This template inserts one or more HTML anchors in a page at the location of its invocation, enabling direct #Links to this location.

Code
Before{{Anchor|Foo|Bar & Baz|Three}}After
Gives
BeforeAfter

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 a bold error message to let you know about it instead of silently ignoring your extra anchors.

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.

Linking

After that, you can have links sending directly to the line you marked:

  • With [[#Bar & Baz|link label]] when linking from the same page
  • With [[Article name#Bar & Baz|link label]] when linking from another page

Technical notes

  • The template is based on <SPAN ID="anchor" />
  • The final HTML page (as outputted by Wikipedia to the reader's browser) will have converted it to <SPAN ID="anchor"></SPAN> instead.
  • The more backward-compatible <A NAME="anchor" ID="anchor"></A> is used by Wikipedia's own headings but disabled for editors in the wikicode and thus not used here.

Template:Pp-semi-protected


fr:Modèle:Ancre de:Vorlage:Anker ru:Шаблон:Anchor sl:Predloga:Sidro