跳转到内容
本页使用了标题或全文手工转换

Template: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.

參見

Cookie帮助我们提供我们的服务。通过使用我们的服务,您同意我们使用cookie。