Template:URL2

本页使用了标题或全文手工转换
维基百科,自由的百科全书
文档图示 模板文档[查看] [编辑] [历史] [清除缓存]

概要

Template:URL的修改版,适合用于信息框。与其类似,不同点是:

  • 参数省略或为空时不显示任何内容。Template:URL则默认显示{{URL|example.com|可选的显示文本}}
  • 提供一个|msg=参数,可开启或关闭{{URL|example.com|可选的显示文本}}的显示。msg参数为false或者任何以字母n或N开头,都会关闭消息,其他内容则使消息为打开状态。
  • 提供的url参数中的html标签和wiki内部链接标签会被去除。
  • url参数在首个空格处截止。
  • 可以将自身的输出作为输入,从而可以在信息框的网站参数中嵌套使用,避免编者在条目中二次添加如|website={{URL|some.url.com}}的代码会导致的解析错误。

用法

  • {{URL2|url}}
  • {{URL2|1=url}}

範例

与Template:URL的差异

无输入值时,URL2默认不显示任何内容(|msg=参数可控制显示)。

  • {{URL2| }}
  • {{URL2|msg=yes| }}{{URL|example.com|可选的显示文本}}
  • {{URL2|msg=true| }}{{URL|example.com|可选的显示文本}}
  • {{URL2|msg=1| }}{{URL|example.com|可选的显示文本}}

URL2能处理信息框中的|website=会遇到的常见的格式:

  • {{URL2|http://www.example.com|website}}website

相同之处

模板将输出放入<span class="url">...</span>并在每个句号前加入<wbr/>元素:

  • {{URL2|www.example.com}}www.example.com
    <span class="url">[http://www.example.com www<wbr/>.example<wbr/>.com]</span>

The use of http://, https://, a protocol-relative URL, or a different protocol is preserved in the URL but is not shown in the link text:

  • {{URL2|http://www.example.com}}www.example.com
    <span class="url">[http://www.example.com www<wbr/>.example<wbr/>.com]</span>
  • {{URL2|https://www.example.com}}www.example.com
    <span class="url">[https://www.example.com www<wbr/>.example<wbr/>.com]</span>
  • {{URL2|//www.example.com}}www.example.com
    <span class="url">[//www.example.com www<wbr/>.example<wbr/>.com]</span>
  • {{URL2|ftp://ftp.example.com}}ftp.example.com
    <span class="url">[ftp://ftp.example.com ftp<wbr/>.example<wbr/>.com]</span>

If the path is only a slash (/) it is not displayed in the link text:

  • {{URL2|https://www.example.com/}}www.example.com
    <span class="url">[https://www.example.com/ www<wbr/>.example<wbr/>.com]</span>

The template also adds <wbr/> before any displayed slashes (/) in the path:

  • {{URL2|https://www.example.com/path}}www.example.com/path
    <span class="url">[https://www.example.com/path www<wbr/>.example<wbr/>.com<wbr/>/path]</span>

For a URL containing an equal sign (=), use |1=:

  • {{URL2|1=http://www.example.com/path?section=17}}www.example.com/path?section=17
    <span class="url">[http://www.example.com/path?section=17 www<wbr/>.example<wbr/>.com<wbr/>/path?section=17]</span>

注意事项

重定向

模板编辑说明

微格式

此模板给显示的URL加上class="url"

參見