跳至內容
本頁使用了標題或全文手工轉換

模板:Namespace detect

快捷方式
Template:NSD

這是{{Namespace detect}}元模板,它可以幫助其他模板檢測出它們被引用的頁面命名空間,並針對不同命名空間顯示透過參數指定的文本。

大致用法如下所示:

{{namespace detect
| 參數名  = 模板被包含在該參數對應的命名空間時所顯示的文本
}}

本模板支持的參數如下所示:

  • main:主/條目命名空間。
  • talk:討論命名空間,包括但不限於「Talk:」「User_talk:」「Wikipedia_talk:」開頭的頁面。
  • pseudo偽命名空間
    • mos, lta:分別對應「MOS:」和「LTA:」開頭的頁面。
  • user, wikipedia, file, mediawiki, template, help, category, portal, wikiproject:分別對應使用者命名空間、計劃命名空間(維基百科命名空間)、檔案命名空間、MediaWiki命名空間、模板命名空間、幫助命名空間、分類命名空間、主題命名空間和維基專題命名空間。
  • other = 如果對應的命名空間參數沒有值,則使用此參數。

為了向下相容,本模板仍能理解file命名空間的舊名稱image,但其現已棄用。

注意:由於此模板容易出現人為錯誤(如參數名拼寫錯誤),所以對於大部分使用情況,最好使用更簡單的命名空間檢測模板,見下列的參見部分。

用法

{{namespace detect
| main  = 條目
| talk  = 討論頁
| other = 其他頁面
}}

如果本模板用於主(條目)頁面上,將返回:

條目

如果本模板用於非條目和討論命名空間的其他頁面上,將返回:

其他頁面

上面的範例中,該模板對於所有命名空間都會返回文本。但如果不使用other參數或者留空,那麼它將不會返回任何文本,如下所示:

{{namespace detect
| file     = 檔案
| category = 分類頁面
| other    =
}}

這個例子中,在除檔案和分類命名空間以外的任何頁面上, 這些代碼都將不返回任何文本。

透過將參數留空,可以在特定命名空間的頁面上不呈現任何內容,如下所示:

{{namespace detect
| main  = 
| other = 其他頁面
}}

上面的代碼在主空間(條目)頁上將不會呈現任何內容,但是在其他頁面上將返回如下內容:

其他頁面

演示空間

該模板提供了demospace參數以供演示用。該參數的值可以是該模板可以理解的任何一個頁面命名空間參數(包括other)。一旦使用該參數,模板便會認為它被包含在該參數指定的命名空間中並呈現相應的文本,如下所示:

{{namespace detect 
| main  = 條目
| other = 其他頁面
| demospace = main
}}

無論以上代碼被包含在什麼命名空間中,都將呈現如下文本:

條目

您可以在自己的模板中將demospace參數傳遞給本模板,如下所示:

{{namespace detect 
| main  = 條目
| other = 其他頁面
| demospace = {{{demospace|}}}
}}

如果demospace參數為空,本模板會忽略該參數。

參數

所有參數列表:

{{namespace detect
| main  = 
...
| other =
| demospace = {{{demospace|}}} / main / talk / user / 
              wikipedia / file / mediawiki / template / 
              help / category / portal / other
}}

Note: Empty values to the "main" ... "portal" parameters do have special meaning.

技術細節

Namespace "Image" was renamed to "File" on 11 December 2008. This template was updated to understand both names well before that, thus it still works fine. For backwards compatibility it still understands "image" both as a parameter name, such as "image = File page text", and as a value "demospace = image".

If you intend to feed tables as content to the numbered parameters of this template, then you need to know this:

Templates do have a problem to handle parameter data that contains pipes "|", unless the pipe is inside another template {{name|param1}} or inside a piped link [[帮助:模板|help]]. Thus templates can not handle wikitables as input unless you escape them by using the Template:Tn template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "HTML wikimarkup" for the table code, which is more robust.

For more technical details such as about "copying to other projects" and "CSS based namespace detection" see {{main talk other}} and its talk page.

參見

Cookies 幫助我們給予服務內容。依您有使用我們的服務,代表您同意我們使用 cookies。