模板:Namespace detect/doc

来自中文乐谱库

Lua错误:无法创建进程:proc_open(/dev/null): failed to open stream: Operation not permitted[[Category:模板:SUBJECTSPACE ZH说明文件]] Lua错误:无法创建进程:proc_open(/dev/null): failed to open stream: Operation not permitted

这是{{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: