求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

模板:Namespace detect檢視原始碼檢視歷史

事實揭露 揭密真相
前往: 導覽搜尋
Template documentation[view] [edit] [history] [purge]

這是{{namespace detect}}元模板。

它可以幫助其他模板檢測出它們的頁面類型。

檢測並將所有在求真百科上使用的不同namespaces組合在一起:

main = 主/條目空間, 如求真百科上的普通條目。
talk = 任何討論頁,比如那些以"Talk:"、"User talk:"、"File talk:"等開頭的頁面。
user, wikipedia, file, mediawiki, template, help, category and portal = 除了討論頁之外的其他命名空間。
other = 任何未指定模板參數的命名空間。見下列解釋。

為了向下兼容,本模板仍能理解file中的 image舊名稱。但image現已棄用。

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

用法

本模板採用上述不同頁面類型命名的一個或多個參數。如下所示:

{{namespace detect
| main  = Article text
| talk  = Talk page text
| other = Other pages text
}}

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

Article text

如果本模板用於非條目、非討論的其他頁面上,將返回:

Other pages text

上面的示例使模板返回所有頁面類型的東西。但如果我們不使用other參數或者留空,那麼它將不返回任何其他頁面類型。如下所示:

{{namespace detect
| file     = File page text
| category = Category page text
| other    =
}}

除文件和類別以外的任何頁面上, 上面的代碼都將不呈現任何內容。

通過使用空參數,特定頁面類型的模板將無法呈現。如下所示:

{{namespace detect
| main  = 
| other = Other pages text
}}

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

Other pages text

演示空間

For testing and demonstration purposes this template can take a parameter named demospace. Demospace understands any of the page type names used by this template, including the other type. It tells the template to behave like it is on some specific type of page. Like this:

{{namespace detect 
| main  = Article text
| other = Other pages text
| demospace = main
}}

No matter on what kind of page the code above is used it will return this:

Article text

It can be convenient to let your template understand the demospace parameter and send it on to the {{namespace detect}} template. Then do like this:

{{namespace detect 
| main  = Article text
| other = Other pages text
| demospace = {{{demospace|}}}
}}

If the demospace parameter is empty or undefined then the template will detect page types as usual.

參數

所有參數列表:

{{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. 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.

參見

便於偵測名字空間的模板群:

更複雜的名字空間偵測模板:

Technical stuff: