Difference between revisions of "Template:Encodelink"

From blackwiki
Jump to navigation Jump to search
imported>ZLEA
(Attempting fix)
imported>ZLEA
(Undid revision 921052359 by ZLEA (talk) Fix did not work)
 
Line 10: Line 10:
 
       |s={{{1|http://en.wikipedia.org/w/index.php?title=2+2=5}}}|i=43|j=-1}} }}
 
       |s={{{1|http://en.wikipedia.org/w/index.php?title=2+2=5}}}|i=43|j=-1}} }}
 
   |<!--else-->http://{{
 
   |<!--else-->http://{{
     urlencode:{{#invoke:String|sub|s={{{1|}}}|i=8|j=-1}} }}
+
     urlencode:{{#invoke:String|sub|s={{{1}}}|i=8|j=-1}} }}
}} {{{2|}}}]<noinclude>
+
}} {{{2}}}]<noinclude>
  
 
The '''[[Template:Encodelink]]''' generates a weblink, of the form "[http:__]" but with the [[URL address]] encoded to handle special characters (such as spaces or plus sign "+" or square brackets "[_]" in the URL). Parameter 1 is the URL, and parameter 2 is the link-text to display.
 
The '''[[Template:Encodelink]]''' generates a weblink, of the form "[http:__]" but with the [[URL address]] encoded to handle special characters (such as spaces or plus sign "+" or square brackets "[_]" in the URL). Parameter 1 is the URL, and parameter 2 is the link-text to display.

Latest revision as of 15:17, 13 October 2019

[Expression error: Unrecognized punctuation character "[". {{{2}}}]

The Template:Encodelink generates a weblink, of the form "[http:__]" but with the URL address encoded to handle special characters (such as spaces or plus sign "+" or square brackets "[_]" in the URL). Parameter 1 is the URL, and parameter 2 is the link-text to display.

Usage: {{encodelink|http://x.com|my link}} → [http://x.com my link]   shows as:  my link

If a URL contains a slash, then the first 42 characters are copied verbatim, and the remainder of the URL is encoded for special characters. Each special character is encoded as %-notation, where '+' is %2B, each left square bracket '[' is %5B, or each right square bracket ']' is %5D.

Examples

The following example uses special characters:

  • {{encodelink|http://en.wikipedia.org/w/index.php?title=2+2=4&action=edit|Edit 2+2=4}} → [//en.wikipedia.org/w/index.php?title=2%2B2%3D4&action=edit Edit 2+2=4] shows as:  Edit 2+2=4

Note that although the special characters are encoded, as percent notation, they might be considered invalid characters for a particular website. Each website has its own rules for the allowable valid names or options. Also, if part of the URL is already encoded, then it will become double-encoded, so a slash "/" already encoded as "%2F" will become "%252F" where the percent sign '%' is %25.

See also