跳至內容

模板: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"

參見