模板:Infobox/doc:修订间差异
更多操作
测试 |
修正模板数据 |
||
| (未显示同一用户的6个中间版本) | |||
| 第1行: | 第1行: | ||
{{From_Wikipedia}} | |||
{{tlf|Infobox}}是构建信息框的元模板,它用来构建一个像<nowiki>{{Infobox 一些主题}}</nowiki>的模板,比如{{tl|Infobox_settlement}}。 | |||
此模板是信息框的元模板:它用来构建其他信息框模板。'''注意''':此模板通常不应直接在条目中使用,但若需要,可在一次性情况中直接使用。[[wikipedia:Help:Infobox]]中包含关于信息框内容和设计的介绍。[[wikipedia:Wikipedia:Manual_of_Styles/Infoboxes]]中包含附加格式指南。参见[[:Category:信息框模板]]查看已有的信息框模板。 | |||
== 使用 == | == 使用 == | ||
{{ | 对于{{tnull|Infobox 一些主题}},经过简化的模板代码看起像这样: | ||
<pre> | <pre> | ||
{{Infobox | {{Infobox | ||
| name = {{{name|{{PAGENAME}}}}} | | name = {{{name|{{PAGENAME}}}}} | ||
| image = {{{image|}}} | | image = {{{image|}}} | ||
| caption1 = {{{caption| | | caption1 = {{{caption|}}} | ||
| label1 = | | label1 = 前名 | ||
| data1 = {{{former_names|}}} | | data1 = {{{former_names|}}} | ||
| header2 = | | header2 = 一般信息 | ||
| label3 = | | label3 = 状态 | ||
| data3 = {{{status|}}} | | data3 = {{{status|}}} | ||
... <!-- etc. --> | ... <!-- etc. --> | ||
| 第25行: | 第24行: | ||
</pre> | </pre> | ||
== | == 参数 == | ||
=== 可选控制参数 === | |||
; name | ; name | ||
: | : 如果此参数存在,“查看·编辑·讨论”链接显示在信息框底部,链接指向此参数指定的页面。如果未在此参数中指定命名空间,则在链接前添加“<code>Template:</code>”(模板)前缀。可使用<nowiki>{{subst:PAGENAME}}</nowiki>;但这不太可能是你希望的,因为点击链接的用户会被导向模板页面/代码,而不是他们可能希望更改的条目中的信息框数据。 | ||
; | ; child | ||
: | : 详细信息参见[[#嵌入|嵌入]]一节。如果此参数设置为“yes”,这个子信息框应该含有标题,不含name参数。此参数默认为空。 | ||
; subbox | |||
: 详细信息参见[[#子盒|子盒]]一节。如果此参数设置为“yes”,这个子信息框应该含有标题,不含name参数。此参数默认为空。 | |||
; decat | ; decat | ||
: | : 如果此参数设置为“yes”,生成的信息框有问题,或不含有可见数据时,当前页面将不会被自动分类进维护分类中。此参数默认为空。 | ||
; autoheaders | |||
: 如果此参数设置为任意非空值,则后面没有data字段的header会被隐藏。详细信息参见“[[#在下方所有数据字段都为空时隐藏顶栏|在下方所有数据字段都为空时隐藏顶栏]]”一节。 | |||
== 内容参数 == | === 内容参数 === | ||
=== 标题 === | ==== 标题 ==== | ||
有两种不同的在信息框中放置标题的方法。一种会将标题放置在信息框表格内最上面的单元格,另一种放置在表格上方。你可以同时使用这两种方法,或只使用其中一种,或者——尽管不推荐——都不用: | |||
; title | ; title | ||
: | : 放置在表格上方的标题文本(如果这是个子信息框,则作为整个表格内容的区域标题) | ||
; above | ; above | ||
: | : 放置在表格内最上面单元格的文本。 | ||
; subheader | ; subheader<var>n</var> | ||
: | : 附加标题字段,显示在title和above之下,图像之上。 | ||
示例: | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| name = Infobox/doc | | name = Infobox/doc | ||
| title | | title = 信息框上方的标题 | ||
| subheader | | subheader = 信息框的子标题 | ||
| header = | | header = (信息框的其他部分) | ||
}} | }} | ||
<pre> | </pre> | ||
{{Infobox | {{Infobox | ||
| name = | | name = Infobox/doc | ||
| title | | title = 信息框上方的标题 | ||
| subheader | | subheader = 信息框的子标题 | ||
| header = | | header = (信息框的其他部分) | ||
}} | }} | ||
{{Clear}} | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| name = Infobox/doc | | name = Infobox/doc | ||
| above | | above = 信息框内最上方单元格的文本 | ||
| subheader | | subheader = 信息框的子标题 | ||
| subheader2 = | | subheader2 = 信息框第2个子标题 | ||
| header = | | header = (信息框的其他部分) | ||
}} | }} | ||
<pre> | </pre> | ||
{{Infobox | {{Infobox | ||
| name = | | name = Infobox/doc | ||
| | | title = 信息框内最上方单元格的文本 | ||
| subheader | | subheader = 信息框的子标题 | ||
| subheader2 = | | subheader2 = 信息框第2个子标题 | ||
| header = | | header = (信息框的其他部分) | ||
}} | }} | ||
{{Clear}} | |||
==== 插图 ==== | |||
; image<var>n</var> | |||
: 显示在模板顶部的图像。使用完整图像语法,例如<code><nowiki>[[File:Example.png|200px|alt=示例替代文本]]</nowiki></code>。图像默认居中。参见[[wikipedia:WP:ALT]]获取关于替代文本的更多信息。 | |||
; caption<var>n</var> | |||
: 图像下面的描述文本。 | |||
==== 主要数据 ==== | |||
; header<var>n</var> : 在第<var>n</var>行作为顶栏的文本。 | |||
; label<var>n</var> : 在第<var>n</var>行作为标签的文本。 | |||
; data<var>n</var> : 在第<var>n</var>行显示为数据的文本。 | |||
注意:在单行(比如第<var>n</var>行)中,不是所有参数组合都可用。{{para|header<var>n</var>}}会与对应的{{para|data<var>n</var>}}(以及{{para|label<var>n</var>}}、{{para|rowclass<var>n</var>}},见下)冲突,使得{{para|data<var>n</var>}}不会显示;缺少{{para|data<var>n</var>}}会隐藏对应的{{para|label<var>n</var>}}。在单行中可用的组合有: | |||
* {{para|class<var>n</var>}} {{para|header<var>n</var>}} | |||
* {{para|rowclass<var>n</var>}} {{para|class<var>n</var>}} {{para|data<var>n</var>}} | |||
* {{para|rowclass<var>n</var>}} {{para|label<var>n</var>}} {{para|class<var>n</var>}} {{para|data<var>n</var>}} | |||
可在下方[[#示例|示例]]章节查看header4、label4和data4的显示情况。 | |||
==== 编号范围 ==== | |||
在顶栏和标签/数据行的编号中使用不连续编号可以在修改信息框时增加灵活性。之后如果需要插入新行,先前使用不连续编号的信息框就不用为已存在的所有参数重新编号了。例如: | |||
<pre> | |||
| header3 = 区域 1 | |||
| label5 = 标签 A | |||
| data5 = 数据 A | |||
| label7 = 标签 C | |||
| data7 = 数据 C | |||
| header10 = 区域 2 | |||
| label12 = 标签 D | |||
| data12 = 数据 D | |||
</pre> | </pre> | ||
也可以自动重新编号参数名,使用[[wikipedia:User:Frietjes/infoboxgap.js]]或者[[wikipedia:Module:IncrementParams]]。 | |||
: | 编号没有最大限制,但在两个编号之间最多只能相差50。 | ||
=== | ==== 可选的数据字段 ==== | ||
只有标签,没有数据的行不会显示。这样可以简单地创建选填的信息。要使一行可选,填写一个默认为空的数据参数就行,像这样: | |||
<pre> | |||
| label5 = 人口 | |||
| data5 = {{{population|}}} | |||
</pre> | |||
这样的话,当条目未提供人口({{para|population}})参数时,信息框的这一行就不会显示。 | |||
对于带有预格式化(除了数据之外还有其他内容)内容的复杂字段,在没有指定参数时它依然会显示。你可以把参数和预设内容都放进“#if”语句里,这样在没有指定参数时,预设内容也不会显示。比如下面的示例中的“#if”语句:“#if(如果):指定了mass参数|显示mass参数,后跟‘ kg’”: | |||
<pre> | <pre> | ||
| | | label6 = 质量 | ||
| data6 = {{ #if: {{{mass|}}} | {{{mass}}} kg }} | |||
| | |||
</pre> | </pre> | ||
==== | <nowiki />#if的更多信息可见于[[mw:Help:Extension:ParserFunctions##if]]和[[metawikimedia:ParserFunctions##if:]]。 | ||
==== 在下方所有数据字段都为空时隐藏顶栏 ==== | |||
也可以让顶栏只在其下方的某个或多个数据单元有内容时才显示。 | |||
考虑这种情况: | |||
<pre> | <pre> | ||
| | {{Infobox | ||
| | | title = 示例:带或不带数据的顶栏 | ||
| headerstyle = background: lightgrey; | |||
| header1 = 带有空区域的header1 | |||
| label2 = label2文本 | data2 = | |||
| label3 = label3文本 | data3 = | |||
| label4 = label4文本 | data4 = | |||
| header5 = 带有下方数data的header5 | |||
| label6 = label6文本 | data6 = 一些值 | |||
}} | |||
</pre> | </pre> | ||
{{Infobox | |||
| title = 示例:带或不带数据的顶栏 | |||
| headerstyle = background: lightgrey; | |||
| header1 = 带有空区域的header1 | |||
| label2 = label2文本 | data2 = | |||
| label3 = label3文本 | data3 = | |||
| label4 = label4文本 | data4 = | |||
| header5 = 带有下方data的header5 | |||
| label6 = label6 文本 | data6 = 一些值 | |||
}} | |||
{{Clear}} | |||
如果你希望在{{para|data<var>n</var>}}没有值时隐藏顶栏,使用{{para|autoheaders|y}}: | |||
<pre> | <pre> | ||
| | {{Infobox | ||
| | | title = 示例:带或不带数据的顶栏 | ||
| autoheaders = y | |||
| headerstyle = background: lightgrey; | |||
| header1 = 带有空区域的header1 | |||
| label2 = label2文本 | data2 = | |||
| label3 = label3文本 | data3 = | |||
| label4 = label4文本 | data4 = | |||
| header5 = 带有下方data的header5 | |||
| label6 = label6文本 | data6 = 一些值 | |||
}} | |||
</pre> | </pre> | ||
{{Infobox | |||
| title = 示例:带或不带数据的顶栏 | |||
| autoheaders = y | |||
| headerstyle = background: lightgrey; | |||
| header1 = 带有空区域的header1 | |||
| label2 = label2文本 | data2 = | |||
| label3 = label3文本 | data3 = | |||
| label4 = label4文本 | data4 = | |||
| header5 = 带有下方data的header5 | |||
| label6 = label6文本 | data6 = 一些值 | |||
| header5 = | |||
| label6 = | |||
}} | }} | ||
{{Clear}} | |||
这样,header1会在data2、data3或data4中任意一个非空时显示。如果3个参数都为空,那么顶栏就不会显示,在到下一个可见内容之前也不会出现空行。 | |||
注意:如果数据含有空HTML元素,像{{para|data|2=<span style="background: yellow;"></span>}},那么这个数据会被视作非空(有数据)。 | |||
如果设置了{{para|autoheader|y}},但你不希望一些项触发顶栏,放置{{para|header<var>X</var>|}}。这会被当做空顶栏并分隔开它与后续项目。 | |||
<pre> | <pre> | ||
{{Infobox | {{Infobox | ||
| title = | | title = 示例:带或不带数据的空顶栏 | ||
| header1 = | | autoheaders = y | ||
| label2 = | | headerstyle = background: lightgrey; | ||
| label3 = | |||
| label4 = | | header1 = 带有空区域的header1 | ||
| header5 = | | label2 = label2文本 | data2 = | ||
| label6 = | | label3 = label3文本 | data3 = | ||
| label4 = label4文本 | data4 = | |||
| header5 = _BLANK_ | |||
| label6 = label6文本 | data6 = 一些值,但不会触发header1或者显示header5 | |||
}} | }} | ||
</pre> | </pre> | ||
{{Infobox | |||
| title = 示例:带或不带数据的空顶栏 | |||
| autoheaders = y | |||
| headerstyle = background: lightgrey; | |||
| header1 = 带有空区域的header1 | |||
| label2 = label2文本 | data2 = | |||
| label3 = label3文本 | data3 = | |||
| label4 = label4文本 | data4 = | |||
| header5 = _BLANK_ | |||
| label6 = label6文本 | data6 = 一些值,但不会触发header1或者显示header5 | |||
}} | |||
{{Clear}} | |||
==== 信息框脚 ==== | |||
; below : 放置在底部单元格的文本。底部单元格用于放置脚注、另见和其他类似信息。 | |||
=== 显示参数 === | |||
==== 斜体标题 ==== | |||
通过传递<code>italic title</code>参数,带有信息框条目的标题可显示为斜体,符合[[wikipedia:WP:ITALICTITLE|WP:ITALICTITLE]]。 | |||
* 在信息框中传递{{para|italic title|<nowiki>{{{italic title|}}}</nowiki>}}来启用斜体标题。 | |||
* 传递{{para|italic title|<nowiki>{{{italic title|no}}}</nowiki>}}默认禁用斜体标题(特别是因为只有拉丁文字可以安全地以这种样式显示,而且可能需要斜体来区分外语和本地英语,而其他文字的斜体可能很难阅读),但可在一些情况下启用。 | |||
* 不传递此参数来禁用全部斜体标题。 | |||
==== 模板样式 ==== | |||
模板样式参数{{para|templatestyles}}、{{para|child templatestyles}}和{{para|grandchild templatestyles}}接收模板样式页的名称(例如<samp>Template:Example/styles.css</samp>),并转换为模板样式标签(<samp><templatestyles src="Template:Example/styles.css" /></samp> )。模板样式在样式化信息框时更为强力。 | |||
一些使用规则: | |||
始终在{{para|bodyclass}}中添加这个信息框独有的的类,这样添加到一个信息框的样式就不会“泄露”到另一个信息框中。例如,[[Template:Infobox_settlement]]含有<code>.infobox-settlement</code>类,[[Template:Infobox_settlement/styles.css|信息框模板样式]]的所有CSS选择器都需要匹配这个类。 | |||
这些标签以这个顺序加载: | |||
# 核心模板样式([[Module:Infobox/styles.css]]) | |||
# 一般模板样式({{para|templatestyles}}) | |||
# 子模板样式({{para|child templatestyles}}) | |||
# 孙模板样式({{para|grandchild templatestyles}}) | |||
因此,这些样式表可以“层叠”。 | |||
; templatestyles : 为直接调用{{tlf|Infobox}}的模板或模块添加的模板样式。 | |||
; child templatestyles : 在模板/模块调用的信息框已有{{para|templatestyles}}时,为模板/模块添加额外模板样式。 | |||
; grandchild templatestyles : 在模板/模块调用的信息框已有{{para|child templatestyles}}时,为模板/模块添加额外模板样式。 | |||
===== 模板样式参数使用示例 ===== | |||
一个无需支持子模板的信息框(无论是它没有子模板还是不想要子模板): | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| title | | title = {{{name|示例信息框}}} | ||
| bodyclass = infobox-example | |||
| | | templatestyles = Template:Infobox_example/styles.css | ||
| | |||
}} | }} | ||
</pre> | |||
一个需要支持子模板的信息框: | |||
<pre> | <pre> | ||
{{Infobox | {{Infobox | ||
| title | | title = {{{name|示例信息框}}} | ||
| bodyclass = infobox-example {{{class|}}} | |||
| | | templatestyles = Template:Infobox_example/styles.css | ||
| | | child templatestyles = {{{child templatestyles|}}} | ||
| | |||
}} | }} | ||
</pre> | </pre> | ||
< | 它的一个子信息框: | ||
<pre> | |||
{{Infobox_example | |||
| title = {{{name|示例子信息框}}} | |||
| bodyclass = infobox-example-child | |||
| child templatestyles = Template:Infobox_example_child/styles.css | |||
}} | |||
</pre> | |||
这样子信息框可以添加它独有的类和模板样式,叠起来了! | |||
支持孙模板的方法是类似的,模板需要额外传递{{para|grandchild templatestyles}}参数,而子模板也需要传递{{para|bodyclass}}和{{para|grandchild templatestyles}}。 | |||
=== | ==== CSS样式 ==== | ||
; | ; bodystyle : 应用到整个信息框表格 | ||
: | ; titlestyle : 仅应用到表格上方的标题。添加背景颜色通常是不明智的,因为文本会显示在消息框'''外'''。 | ||
; | ; abovestyle : 仅应用到信息框顶部单元格。默认样式有<code>font-size: 125%</code>;因为此单元格通常用于标题。如果你希望将此单元格的文本改为正常大小,在abovestyle里包含“<code>font-size: 100%</code>”。 | ||
: | ; subheaderstyle : 应用到所有子标题单元格 | ||
; | ; imagestyle : 应用到图像所在的单元格,包括图像描述。在设置图像描述的文本属性时应使用captionstyle,而不是imagestyle,以防止未来图像描述移出此单元格。 | ||
: | ; captionstyle : 应用到图像描述文本。 | ||
; | ; rowstyle<var>n</var> : 此参数插入到指定行的<code>style</code>属性中。 | ||
: | ; headerstyle : 应用到所有顶栏单元格 | ||
; | ; labelstyle : 应用到所有标签单元格 | ||
: | ; datastyle : 应用到所有数据单元格 | ||
; | ; belowstyle : 仅应用到信息框底部单元格 | ||
: | |||
; | |||
: | |||
; | |||
: | |||
; | |||
: | |||
; | |||
: | |||
==== HTML类和微格式 ==== | |||
; bodyclass : 此参数插入到信息框(即{{tag|table|attribs=class="infobox ..."}})的<code>class</code>属性中。 | |||
; titleclass : 此参数插入到信息框'''外部标题'''的<code>class</code>属性中。<!-- | |||
当前的Lua模块未实现 | |||
; aboverowclass : 此参数插入到'''above'''单元格所在的整个表格行的<code>class</code>属性中。 | |||
--> | |||
; aboveclass : 此参数插入到信息框'''above'''单元格的<code>class</code>属性中。 | |||
; subheaderrowclass<var>n</var> : 此参数插入到'''子标题'''所在的整个表格行的<code>class</code>属性中。 | |||
; subheaderclass<var>n</var> : 此参数插入到信息框'''子标题'''的<code>class</code>属性中。 | |||
; imagerowclass<var>n</var> : 此参数插入到'''图像'''所在的整个表格行的<code>class</code>属性中。 | |||
; imageclass : 此参数插入到'''图像'''的<code>class</code>属性中。 | |||
; rowclass<var>n</var> : 此参数插入到指定行的<code>class</code>属性中,包括'''label'''和'''data'''单元格。 | |||
; class<var>n</var> : 此参数插入到指定行中'''data'''的<code>class</code>属性中。如果没有'''data'''单元格就不会生效。<!-- | |||
当前的Lua模块未实现 | |||
; belowrowclass : 此参数插入到'''below'''单元格所在的整个表格行的<code>class</code>属性中。 | |||
--> | |||
; belowclass : 此参数插入到信息框'''below'''单元格的<code>class</code>属性中。 | |||
此模板支持附加微格式信息。这是通过为不同data单元格添加“class”属性来实现的,不同的class属性可以指示相关数据单元格包含何种类型的信息。可以指定多个类名,使用空格分隔,其中一些类作为CSS选择器,附加相关样式,另一些用于微格式。 | |||
<pre> | 要标记一个信息框包含[[wikipedia:hCard|hCard]]信息,作为示例,添加下方参数: | ||
<pre> | |||
| bodyclass = vcard | |||
</pre> | |||
为于每行包含属于vcard一部分的data单元格,添加一个相应的class参数: | |||
<pre> | <pre> | ||
| class1 = fn | | class1 = fn | ||
| 第247行: | 第345行: | ||
</pre> | </pre> | ||
. | …等等。通常用于显示信息框主题的“above”和“title”也可以添加类。 | ||
可在[[wikipedia:Wikipedia:WikiProject Microformats]]获取在wiki内添加微格式信息的进一步信息,访问[https://microformats.org 微格式官方网站]亦能获取更一般性的信息。 | |||
== | == 示例 == | ||
注意,当定义了标签但相关的数据单元格为空时,那一行不会显示在信息框中;在一行中同时定义了顶栏、标签和数据时,只有顶栏会显示。也要注意,子标题(subheader)默认不像用于分隔主要数据区域的顶栏(header)那样显示为粗体,因为子标题的角色像顶部单元格(above)。 | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| name | | name = Infobox/doc | ||
| bodystyle | | bodystyle = | ||
| title | |||
| | | titlestyle = | ||
| image | | abovestyle = background: #cfc; | ||
| subheaderstyle = | |||
| caption | | title = 测试信息框 | ||
| above = 顶部文本 | |||
| headerstyle | | subheader = 图像上方的子标题 | ||
| labelstyle | | subheader2 = 第2个子标题 | ||
| datastyle | |||
| imagestyle = | |||
| captionstyle = | |||
| image = [[File:Example.png|200px|alt=示例替代文本]] | |||
| caption = 显示在File:Example.png下方的描述 | |||
| headerstyle = background: #ccf; | |||
| labelstyle = background: #ddf; | |||
| datastyle = | |||
| header1 = 独自定义的顶栏 | | header1 = 独自定义的顶栏 | ||
| label1 | | label1 = | ||
| data1 | | data1 = | ||
| header2 = | | header2 = | ||
| label2 | | label2 = 独自定义的标签,不会显示,只有对应的数据存在时才会显示 | ||
| data2 | | data2 = | ||
| header3 = | | header3 = | ||
| label3 | | label3 = | ||
| data3 | | data3 = 独自定义的数据 | ||
| header4 = | | header4 = 三项均有定义(顶栏) | ||
| label4 | | label4 = 不会显示(因为与顶栏的编号相同) | ||
| data4 | | data4 = 不会显示(因为与顶栏的编号相同) | ||
| header5 = | | header5 = | ||
| label5 | | label5 = 定义的标签和数据(标签) | ||
| data5 | | data5 = 定义的标签和数据(数据) | ||
| belowstyle = background:#ddf; | | belowstyle = background: #ddf; | ||
| below = | | below = 底部文本 | ||
}} | }} | ||
<pre> | </pre> | ||
{{Infobox | {{Infobox | ||
| name | | name = Infobox/doc | ||
| bodystyle | | bodystyle = | ||
| title | |||
| | | titlestyle = | ||
| image | | abovestyle = background: #cfc; | ||
| subheaderstyle = | |||
| caption | | title = 测试信息框 | ||
| above = 顶部文本 | |||
| headerstyle | | subheader = 图像上方的子标题 | ||
| labelstyle | | subheader2 = 第2个子标题 | ||
| datastyle | |||
| imagestyle = | |||
| captionstyle = | |||
| image = [[File:Example.png|200px|alt=示例替代文本]] | |||
| caption = 显示在File:Example.png下方的描述 | |||
| headerstyle = background: #ccf; | |||
| labelstyle = background: #ddf; | |||
| datastyle = | |||
| header1 = 独自定义的顶栏 | | header1 = 独自定义的顶栏 | ||
| label1 | | label1 = | ||
| data1 | | data1 = | ||
| header2 = | | header2 = | ||
| label2 | | label2 = 独自定义的标签,不会显示,只有对应的数据存在时才会显示 | ||
| data2 | | data2 = | ||
| header3 = | | header3 = | ||
| label3 | | label3 = | ||
| data3 | | data3 = 独自定义的数据 | ||
| header4 = | | header4 = 三项均有定义(顶栏) | ||
| label4 | | label4 = 不会显示(因为与顶栏的编号相同) | ||
| data4 | | data4 = 不会显示(因为与顶栏的编号相同) | ||
| header5 = | | header5 = | ||
| label5 | | label5 = 定义的标签和数据(标签) | ||
| data5 | | data5 = 定义的标签和数据(数据) | ||
| belowstyle = background:#ddf; | | belowstyle = background: #ddf; | ||
| below = | | below = 底部文本 | ||
}} | }} | ||
{{Clear}} | |||
这个示例中,{{para|bodystyle}}和{{para|labelstyle}}参数用来调整信息框宽度,并设定label一列的默认宽度: | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| name | | name = Infobox/doc | ||
| bodystyle | | bodystyle = width: 20em; | ||
| | | titlestyle = | ||
| title = 测试信息框 | |||
| | |||
| headerstyle | | headerstyle = | ||
| labelstyle | | labelstyle = width: 33%; | ||
| datastyle | | datastyle = | ||
| header1 = | | header1 = | ||
| label1 = 标签1 | |||
| data1 = 数据1 | |||
| header2 = | | header2 = | ||
| label2 = | | label2 = 标签2 | ||
| data2 = | | data2 = 数据2 | ||
| header3 = | | header3 = | ||
| label3 = | | label3 = 标签3 | ||
| data3 = | | data3 = 数据3 | ||
| header4 = | | header4 = 顶栏4 | ||
| label4 = | | label4 = | ||
| data4 = | | data4 = | ||
| header5 = | | header5 = | ||
| label5 = | | label5 = 标签5 | ||
| data5 = | | data5 = 数据5: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
| belowstyle = | | belowstyle = | ||
| below | | below = 底部文本 | ||
}} | }} | ||
<pre> | </pre> | ||
{{Infobox | {{Infobox | ||
| name | | name = Infobox/doc | ||
| bodystyle | | bodystyle = width: 20em; | ||
| | | titlestyle = | ||
| title = 测试信息框 | |||
| | |||
| headerstyle | | headerstyle = | ||
| labelstyle | | labelstyle = width: 33%; | ||
| datastyle | | datastyle = | ||
| header1 = | | header1 = | ||
| label1 = 标签1 | |||
| data1 = 数据1 | |||
| header2 = | | header2 = | ||
| label2 = | | label2 = 标签2 | ||
| data2 = | | data2 = 数据2 | ||
| header3 = | | header3 = | ||
| label3 = | | label3 = 标签3 | ||
| data3 = | | data3 = 数据3 | ||
| header4 = | | header4 = 顶栏4 | ||
| label4 = | | label4 = | ||
| data4 = | | data4 = | ||
| header5 = | | header5 = | ||
| label5 = | | label5 = 标签5 | ||
| data5 = | | data5 = 数据5: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
| belowstyle = | | belowstyle = | ||
| below | | below = 底部文本 | ||
}} | }} | ||
{{Clear}} | |||
== 嵌入 == | == 嵌入 == | ||
信息框可以通过使用{{para|child}}参数嵌入到另一个信息框中。这一功能可用于创建模块化信息框,或者创建逻辑定义更好的区域。很久之前,为了创建有超过99行内容的信息框,需要使用嵌入功能,但现在单一信息框没有行数限制了。 | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| title = | | title = 顶层标题 | ||
| data1 = {{Infobox | decat = yes | child = yes | | data1 = {{Infobox | decat = yes | child = yes | ||
| title = | | title = 第1个子部分 | ||
| label1= | | label1 = 标签1.1 | ||
| data1 = | | data1 = 数据1.1 | ||
}} | |||
| data2 = {{Infobox | decat = yes | child = yes | | data2 = {{Infobox | decat = yes | child = yes | ||
| title | | title = 第2个子部分 | ||
| label1 = | | label1 = 标签2.1 | ||
| data1 | | data1 = 数据2.1 | ||
}} | |||
| belowstyle = | | belowstyle = | ||
| below = 底部文本 | | below = 底部文本 | ||
}} | }} | ||
<pre> | </pre> | ||
{{Infobox | {{Infobox | ||
| title = | | title = 顶层标题 | ||
| data1 = {{Infobox | decat = yes | child = yes | | data1 = {{Infobox | decat = yes | child = yes | ||
| title = | | title = 第1个子部分 | ||
| label1= | | label1 = 标签1.1 | ||
| data1 = | | data1 = 数据1.1 | ||
}} | |||
| data2 = {{Infobox | decat = yes | child = yes | | data2 = {{Infobox | decat = yes | child = yes | ||
| title | | title = 第2个子部分 | ||
| label1 = | | label1 = 标签2.1 | ||
| data1 | | data1 = 数据2.1 | ||
}} | |||
| belowstyle = | | belowstyle = | ||
| below = 底部文本 | | below = 底部文本 | ||
}} | }} | ||
{{Clear}} | |||
注意,上例中,子信息框放置在数据字段中,而非顶栏字段。除非特别指定,否则子信息框标题不会显示为粗体。如需让子部分标题显示为粗体,除了使用CSS外,也可以考虑使用下面的方法: | |||
<pre> | |||
{{Infobox | {{Infobox | ||
| title = | | title = 顶层标题 | ||
| header1 | | header1 = 第1个子部分 | ||
| data2 = {{Infobox | decat = yes | child = yes | |||
| label1 = 标签1.1 | |||
| data1 = 数据1.1 | |||
| | |||
| label1 = | |||
| data1 | |||
}} | }} | ||
| header3 = 第2个子部分 | |||
| data4 = {{Infobox | decat = yes | child = yes | |||
| label1 = 标签2.1 | |||
| data1 = 数据2.1 | |||
| | |||
| | |||
| label1 = | |||
| | |||
}} | }} | ||
| belowstyle = | |||
| below = 底部文本 | |||
}} | }} | ||
</pre> | </pre> | ||
{{Infobox | {{Infobox | ||
| title = | | title = 顶层标题 | ||
| header1 = | | header1 = 第1个子部分 | ||
| data2 = {{Infobox | decat = yes | child = yes | |||
| label1 = 标签1.1 | |||
| data1 = 数据1.1 | |||
}} | |||
| | | header3 = 第2个子部分 | ||
| data4 = {{Infobox | decat = yes | child = yes | |||
| label1 = 标签2.1 | |||
| data1 = 数据2.1 | |||
}} | |||
| belowstyle = | | belowstyle = | ||
| below = 底部文本 | | below = 底部文本 | ||
}} | }} | ||
{{Clear}} | |||
在不使用{{para|title}}且不在嵌入的信息框前面添加任何文本的话,可能会在子信息框前生成一个空表格行,在视觉上添加间隙。空表格行可以用{{para|rowstyle<var>n</var>|display: none;}}来隐藏,将<var>n</var>替换为数据行的编号。 | |||
[[wikipedia:Wikipedia:WikiProject Infoboxes/embed]]包含一些链接,指向使用嵌入到其他信息框的信息框的条目。 | |||
== 子盒 == | |||
另一种嵌入方法是使用{{para|subbox|yes}},这种方法移除信息框外部边框,但保留嵌入信息框的内部结构。这种方法的一个特点是子、父信息框不必含有相同的结构,标签和数据字段在两个信息框之间也不会对齐,因为他们的父表格不相同。 | |||
<pre> | <pre> | ||
{{Infobox | {{Infobox | ||
| | | headerstyle = background-color: #eee; | ||
| header1 = | | labelstyle = background-color: #eee; | ||
| header1 = 主 1 | |||
| header2 = 主 2 | |||
| data3 = {{Infobox | subbox = yes | |||
| headerstyle = background-color: #ccc; | |||
-- | | labelstyle = background-color: #ddd; | ||
| header1 = 子 3-1 | |||
| header2 = 子 3-2 | |||
| | | label3 = 标签 3-3 | data3 = 数据 3-3 | ||
| | }} | ||
| data4 = {{Infobox | subbox = yes | |||
| labelstyle = background-color: #ccc; | |||
| label1 = 标签 4-1 | data1 = 数据 4-1 | |||
}} | |||
| label5 = 标签 5 | data5 = 数据 5 | |||
| header6 = 主 6 | |||
}} | }} | ||
</pre> | </pre> | ||
{{Infobox | |||
| headerstyle = background-color: #eee; | |||
| labelstyle = background-color: #eee; | |||
| header1 = 主 1 | |||
| header2 = 主 2 | |||
| data3 = {{Infobox | subbox = yes | |||
| headerstyle = background-color: #ccc; | |||
| labelstyle = background-color: #ddd; | |||
| header1 = 子 3-1 | |||
| header2 = 子 3-2 | |||
| label3 = 标签 3-3 | data3 = 数据 3-3 | |||
}} | |||
| data4 = {{Infobox | subbox = yes | |||
| labelstyle = background-color: #ccc; | |||
| label1 = 标签 4-1 | data1 = 数据 4-1 | |||
}} | |||
| label5 = 标签 5 | data5 = 数据 5 | |||
| header6 = 主 6 | |||
| header1 = | |||
| header2 = | |||
| label3 = | |||
| | |||
| labelstyle = background-color: | |||
| label1 = | |||
| label5 = | |||
| header6 = | |||
}} | }} | ||
{{Clear}} | |||
相似的嵌入技术可以用在其他生成表格的模板的内容参数(例如{{tl|Sidebar}}): | |||
<pre> | <pre> | ||
{{ | {{Sidebar | ||
| | | navbar = off | ||
| | | headingstyle = background-color: #eee; | ||
| | | heading1 = 标题 1 | ||
| | | heading2 = 标题 2 | ||
| | | content3 = {{Infobox | subbox = yes | ||
| headerstyle = background-color: | | headerstyle = background-color:#ccc; | ||
| labelstyle | | labelstyle = background-color:#ddd; | ||
| header1 = | | header1 = 子 3-1 | ||
| header2 = | | header2 = 子 3-2 | ||
| label3 = | | label3 = 标签 3-3 | data3 = 数据 3-3 | ||
}} | |||
| content4 = {{Infobox | subbox = yes | |||
| | | labelstyle = background-color: #ccc; | ||
| labelstyle | | label1 = 标签 4-1 | data1 = 数据 4-1 | ||
| label1 = | }} | ||
| heading5 = 标题 5 | |||
| | |||
}} | }} | ||
</pre> | </pre> | ||
{{Sidebar | |||
| navbar = off | |||
| headingstyle = background-color: #eee; | |||
| heading1 = 标题 1 | |||
| heading2 = 标题 2 | |||
| content3 = {{Infobox | subbox = yes | |||
| headerstyle = background-color:#ccc; | |||
| labelstyle = background-color:#ddd; | |||
| header1 = 子 3-1 | |||
| header2 = 子 3-2 | |||
| label3 = 标签 3-3 | data3 = 数据 3-3 | |||
}} | |||
| content4 = {{Infobox | subbox = yes | |||
| labelstyle = background-color: #ccc; | |||
| label1 = 标签 4-1 | data1 = 数据 4-1 | |||
}} | |||
| heading5 = 标题 5 | |||
}} | |||
{{clear}} | |||
包含每个子盒的父数据单元格的默认内边距依然可见,因此子盒比父盒略窄,并且父盒标准单元格之间的垂直间距比不同子盒单元格之间的垂直间距大。 | |||
== 在嵌入的不带点列表中控制换行 == | |||
{{tlx|nbsp}}模板可以和{{tlx|wbr}}和{{tlx|nowrap}}一起用来控制嵌入在信息框中的不带点列表的换行(例如:[[wikipedia:Template:Infobox film]]中的参演人员列表)。要防止包装的长实体和其他实体之间混淆,参见[[Template:Wbr/doc#控制信息框中的换行]]获取详情。 | |||
== 完整空白语法 == | |||
注意:行编号是无限的,下面只提供20个编号,因为使用更大编号的信息框相对比较少见,在需要时扩展编号就行。微格式“class”参数也省略掉了,因为它们不太常用。 | |||
<pre> | <pre> | ||
{{Infobox | {{Infobox | ||
| name | | name = {{subst:PAGENAME}} | ||
| child | | child = {{{child|}}} | ||
| subbox | | subbox = {{{subbox|}}} | ||
| italic title | | italic title = {{{italic title|no}}} | ||
| bodystyle | | templatestyles = | ||
| child templatestyles = | |||
| grandchild templatestyles = | |||
| bodystyle = | |||
| titlestyle = | |||
| abovestyle = | |||
| subheaderstyle = | |||
| title = | |||
| above = | |||
| subheader = | |||
| title | |||
| above | |||
| subheader | |||
| | | imagestyle = | ||
| captionstyle | | captionstyle = | ||
| | | image = | ||
| caption = | |||
| image2 = | |||
| caption2 = | |||
| | |||
| | |||
| | |||
| belowstyle | | headerstyle = | ||
| below | | labelstyle = | ||
| datastyle = | |||
| header1 = | |||
| label1 = | |||
| data1 = | |||
| header2 = | |||
| label2 = | |||
| data2 = | |||
| header3 = | |||
| label3 = | |||
| data3 = | |||
| header4 = | |||
| label4 = | |||
| data4 = | |||
| header5 = | |||
| label5 = | |||
| data5 = | |||
| header6 = | |||
| label6 = | |||
| data6 = | |||
| header7 = | |||
| label7 = | |||
| data7 = | |||
| header8 = | |||
| label8 = | |||
| data8 = | |||
| header9 = | |||
| label9 = | |||
| data9 = | |||
| header10 = | |||
| label10 = | |||
| data10 = | |||
| header11 = | |||
| label11 = | |||
| data11 = | |||
| header12 = | |||
| label12 = | |||
| data12 = | |||
| header13 = | |||
| label13 = | |||
| data13 = | |||
| header14 = | |||
| label14 = | |||
| data14 = | |||
| header15 = | |||
| label15 = | |||
| data15 = | |||
| header16 = | |||
| label16 = | |||
| data16 = | |||
| header17 = | |||
| label17 = | |||
| data17 = | |||
| header18 = | |||
| label18 = | |||
| data18 = | |||
| header19 = | |||
| label19 = | |||
| data19 = | |||
| header20 = | |||
| label20 = | |||
| data20 = | |||
| belowstyle = | |||
| below = | |||
}} | }} | ||
</pre> | </pre> | ||
== 移植到其他MediaWiki == | |||
{{tlf|Infobox}}依赖于[[mw:Extension:Scribunto]]和[[mw:Extension:TemplateStyles]]扩展,[[mw:Extension:ParserFunction]]扩展很可能也是必需的,所以目标MediaWiki需要安装这三个扩展。你需要复制以下页面: | |||
* [[Template:Infobox]] — 主模板; | |||
** [[Template:Infobox/doc]] — 可选的模板文档,应该也可以直接复制,但安装了[[mw:Extension:TemplateData]]扩展才能支持模板数据。 | |||
* [[Module:Infobox]] — 生成信息框的Lua模块; | |||
* [[Module:Infobox/styles.css]] — 信息框CSS样式。 | |||
Lua模块也有自己的依赖项,全复制过去。 | |||
== 模板数据 == | == 模板数据 == | ||
{{TemplateData header}} | {{TemplateData header}} | ||
<templatedata> | <templatedata> | ||
{ | { | ||
"params": { | "params": { | ||
"name": { | "name": { | ||
"label": "名称", | "label": "名称", | ||
"description": " | "description": "信息框底部“查看·编辑·讨论”链接指向模板的名称,如果不指定命名空间,会在链接前添加“Template:”(模板)前缀。", | ||
" | "type": "line", | ||
"type": " | "autovalue": "{{subst:PAGENAME}}" | ||
}, | |||
"child": { | |||
"label": "子盒式", | |||
"description": "模板是否以子盒格式显示", | |||
"type": "boolean" | |||
}, | }, | ||
" | "embed": { | ||
"label": "嵌入式", | |||
"label": " | "description": "模板是否以嵌入格式显示", | ||
"description": " | "type": "boolean" | ||
"type": " | |||
}, | }, | ||
"decat": { | "decat": { | ||
"label": " | "label": "禁用分类", | ||
"description": " | "description": "模板是否会禁用维护分类", | ||
"type": " | "type": "boolean" | ||
}, | }, | ||
" | "italic title": { | ||
"label": " | "label": "斜体标题", | ||
"description": " | "description": "启用后页面标题会变为斜体", | ||
"type": " | "type": "boolean", | ||
"deprecated": "暂不支持功能" | |||
}, | }, | ||
" | "autoheaders": { | ||
"label": " | "label": "自动顶栏", | ||
"description": " | "description": "启用本功能的话,下方没有非空数据字段的顶栏都会被隐藏。", | ||
"type": " | "type": "boolean" | ||
}, | }, | ||
" | "templatestyles": { | ||
"label": " | "label": "模板样式", | ||
"description": " | "description": "信息框需要加载的模板样式", | ||
"type": " | "example": "Template:Infobox_exmaple/styles.css", | ||
"type": "line" | |||
}, | }, | ||
" | "child templatestyles": { | ||
"label": " | "label": "子模板样式", | ||
"description": " | "description": "子模板加载的模板样式,重复示例中的值就行。使用此功能也需要为bodyclass参数的最后一个类后面添加{{{bodyclass|}}},例如“bodyclass = infobox-example {{{bodyclass|}}}”。", | ||
"type": " | "example": "{{{child templatestyles|}}}", | ||
"type": "line" | |||
}, | }, | ||
" | "grandchild templatestyles": { | ||
"label": " | "label": "孙模板样式", | ||
"description": " | "description": "孙模板加载的模板样式,重复示例中的值就行。详情参见模板文档的“模板样式”一节。", | ||
"type": " | "example": "{{{grand templatestyles|}}}", | ||
"type": "line" | |||
}, | }, | ||
" | "bodyclass": { | ||
"label": " | "label": "整体HTML类", | ||
"description": " | "description": "添加到信息框整体的HTML类", | ||
"type": " | "example": "infobox-settlement vcard", | ||
"type": "line" | |||
}, | }, | ||
" | "bodystyle": { | ||
"label": " | "label": "整体CSS样式", | ||
"description": " | "description": "应用到信息框整体的CSS样式", | ||
"example": "float: none;", | |||
"type": "string" | "type": "string" | ||
}, | }, | ||
" | "titleclass": { | ||
"label": " | "label": "标题HTML类", | ||
"description": " | "description": "添加到信息框外部标题的HTML类", | ||
"type": " | "type": "line" | ||
}, | }, | ||
" | "aboveclass": { | ||
"label": " | "label": "顶部单元格HTML类", | ||
"description": " | "description": "添加到顶部单元格的HTML类", | ||
"type": "string" | "type": "string" | ||
}, | }, | ||
" | "subheaderrowclass2": { | ||
"label": " | "label": "子标题2表格行HTML类", | ||
"description": " | "description": "添加到子标题2所处表格行的HTML类,编号可以继续延长", | ||
"type": " | "type": "line" | ||
}, | }, | ||
" | "subheaderclass2": { | ||
"label": " | "label": "子标题2 HTML类", | ||
"description": " | "description": "添加到子标题2单元格的HTML类,编号可以继续延长", | ||
"type": "line" | |||
}, | }, | ||
" | "titlestyle": { | ||
"label": " | "label": "标题CSS样式", | ||
"description": " | "description": "应用到信息框外部标题的CSS样式", | ||
"type": "string" | "type": "string" | ||
}, | }, | ||
" | "abovestyle": { | ||
"label": " | "label": "顶部单元格CSS样式", | ||
"description": " | "description": "应用到顶部单元格的CSS样式", | ||
"type": " | "type": "line" | ||
}, | }, | ||
" | "subheaderstyle": { | ||
"label": " | "label": "子标题CSS样式", | ||
"description": " | "description": "应用到所有子标题的CSS样式" | ||
}, | }, | ||
"title": { | "title": { | ||
"label": "标题 | "label": "标题", | ||
" | "description": "信息框外部标题", | ||
" | "type": "content" | ||
}, | }, | ||
"above": { | "above": { | ||
"label": " | "label": "顶部单元格", | ||
" | "description": "信息框最上方的单元格(内部标题)", | ||
" | "type": "content" | ||
}, | }, | ||
" | "subheader": { | ||
"label": " | "aliases": [ | ||
"type": " | "subheader1" | ||
], | |||
"label": "子标题1", | |||
"description": "信息框的第1个子标题", | |||
"type": "content" | |||
}, | }, | ||
"subheaderrowclass": { | "subheaderrowclass": { | ||
"label": " | "aliases": [ | ||
"description": " | "subheaderrowclass1" | ||
"type": " | ], | ||
"label": "子标题1表格行HTML类", | |||
"description": "添加到子标题1所处表格行的HTML类", | |||
"type": "line" | |||
}, | }, | ||
"subheaderclass": { | "subheaderclass": { | ||
"label": " | "aliases": [ | ||
"description": " | "subheaderclass1" | ||
"type": " | ], | ||
"label": "子标题1 HTML类", | |||
"description": "添加到子标题1单元格的HTML类", | |||
"type": "line" | |||
}, | |||
"subheader2": { | |||
"label": "子标题2", | |||
"description": "信息框的第2个子标题,编号可以继续延长", | |||
"type": "content" | |||
}, | |||
"imagerowclass": { | |||
"aliases": [ | |||
"imagerowclass1" | |||
], | |||
"label": "图像1表格行HTML类", | |||
"description": "添加到图像1所处表格行的HTML类", | |||
"type": "line" | |||
}, | |||
"imagerowclass2": { | |||
"label": "图像2表格行HTML类", | |||
"description": "添加到图像2所处表格行的HTML类", | |||
"type": "line" | |||
}, | }, | ||
" | "imageclass": { | ||
"label": " | "label": "图像HTML类", | ||
"type": " | "description": "添加到所有图像单元格的HTML类", | ||
"type": "line" | |||
}, | }, | ||
" | "imagestyle": { | ||
"label": " | "label": "图像CSS样式", | ||
" | "description": "应用到所有图像单元格的CSS样式", | ||
"type": "line" | |||
}, | }, | ||
" | "captionstyle": { | ||
"label": " | "label": "图像描述CSS样式", | ||
" | "description": "应用到所有图像描述文本的CSS样式", | ||
"type": "line" | |||
}, | }, | ||
"image": { | "image": { | ||
"label": " | "aliases": [ | ||
"description": " | "image1" | ||
"type": " | ], | ||
"label": "图像1", | |||
"description": "第1张图像,信息框图像显示在子标题下。图像使用完整wikitext图像语法。", | |||
"example": "[[File:Example.png|200px|替代文本]]", | |||
"type": "line" | |||
}, | }, | ||
"caption": { | "caption": { | ||
" | "aliases": [ | ||
"caption1" | |||
], | |||
"label": "图像描述1", | |||
"description": "图像1的描述文本", | |||
"label": " | "type": "content" | ||
"description": " | |||
"type": " | |||
}, | }, | ||
"image2": { | "image2": { | ||
"label": " | "label": "图像2", | ||
"description": "第2张图像,编号可以继续延长", | |||
"type": "line" | |||
}, | }, | ||
"caption2": { | "caption2": { | ||
"label": " | "label": "图像描述2", | ||
"description": "图像2的描述文本,编号可以继续延长", | |||
"type": "content" | |||
}, | }, | ||
" | "headerstyle": { | ||
"label": " | "label": "顶栏CSS样式", | ||
" | "description": "应用到所有顶栏单元格的CSS样式", | ||
"type": "line" | |||
}, | |||
"labelstyle": { | |||
"label": "标签CSS样式", | |||
"description": "应用到所有标签单元格的CSS样式", | |||
"type": "line" | |||
}, | |||
"datastyle": { | |||
"label": "数据CSS样式", | |||
"description": "应用到所有数据单元格的CSS样式", | |||
"type": "line" | |||
}, | |||
"rowclass1": { | |||
"label": "行1 HTML类", | |||
"description": "添加到第1个内容行的HTML类", | |||
"type": "line" | |||
}, | |||
"class1": { | |||
"label": "数据1 HTML类", | |||
"description": "应用到数据1单元格的HTML类", | |||
"type": "string" | |||
}, | |||
"rowstyle1": { | |||
"label": "行1 CSS样式", | |||
"description": "应用到第1个内容行的CSS样式", | |||
"type": "line" | |||
}, | }, | ||
"header1": { | "header1": { | ||
"label": " | "label": "顶栏1", | ||
"description": " | "description": "位于第1个内容行的顶栏。顶栏居中显示,占用一整行的空间。", | ||
"type": " | "type": "line" | ||
}, | }, | ||
"label1": { | "label1": { | ||
"label": " | "label": "标签1", | ||
"description": " | "description": "位于第1个内容行的标签。标签显示在信息框左侧,如果对应的数据没有内容,就不会显示。当同一行中同时存在顶栏,标签也不会显示。", | ||
"type": " | "type": "line" | ||
}, | }, | ||
"data1": { | "data1": { | ||
"label": " | "label": "数据1", | ||
"description": " | "description": "位于第1个内容行的数据。当对应标签存在时,数据显示在信息框右侧,对应标签不存在时,居中显示,占用一整行的空间。当同一行中同时存在顶栏时,数据不会显示。", | ||
"type": " | "type": "content" | ||
}, | }, | ||
" | "rowclass2": { | ||
"label": " | "label": "行2 HTML类", | ||
"description": " | "description": "添加到第2个内容行的HTML类", | ||
"type": " | "type": "line" | ||
}, | }, | ||
" | "class2": { | ||
"label": " | "label": "数据2 HTML类", | ||
"description": " | "description": "应用到数据2单元格的HTML类", | ||
"type": "string" | "type": "string" | ||
}, | }, | ||
" | "rowstyle2": { | ||
"description": " | "label": "行2 CSS样式", | ||
"type": " | "description": "应用到第2个内容行的CSS样式", | ||
"type": "line" | |||
}, | }, | ||
"header2": { | "header2": { | ||
"label": " | "label": "顶栏2", | ||
" | "description": "位于第2个内容行的顶栏", | ||
"type": "line" | |||
}, | }, | ||
"label2": { | "label2": { | ||
"label": " | "label": "标签2", | ||
" | "description": "位于第2个内容行的标签", | ||
"type": "line" | |||
}, | }, | ||
"data2": { | "data2": { | ||
"label": " | "label": "数据2", | ||
" | "description": "位于第2个内容行的数据", | ||
"type": "content" | |||
}, | }, | ||
" | "rowclass3": { | ||
"label": " | "label": "行3 HTML类", | ||
" | "description": "添加到第3个内容行的HTML类", | ||
"type": "line" | |||
}, | }, | ||
"class3": { | |||
"label": " | "label": "数据3 HTML类", | ||
" | "description": "应用到数据3单元格的HTML类", | ||
"type": "string" | |||
}, | }, | ||
" | "rowstyle3": { | ||
" | "label": "行3 CSS样式", | ||
"description": "应用到第3个内容行的CSS样式", | |||
"type": "line" | |||
}, | }, | ||
"header3": { | "header3": { | ||
"label": " | "label": "顶栏3", | ||
" | "description": "位于第3个内容行的顶栏", | ||
"type": "line" | |||
}, | }, | ||
"label3": { | "label3": { | ||
"label": " | "label": "标签3", | ||
" | "description": "位于第3个内容行的标签", | ||
"type": "line" | |||
}, | }, | ||
"data3": { | "data3": { | ||
"label": " | "label": "数据3", | ||
" | "description": "位于第3个内容行的数据", | ||
"type": "content" | |||
}, | }, | ||
" | "rowclass4": { | ||
"label": " | "label": "行4 HTML类", | ||
" | "description": "添加到第4个内容行的HTML类", | ||
"type": "line" | |||
}, | }, | ||
" | "class4": { | ||
"label": " | "label": "数据4 HTML类", | ||
" | "description": "应用到数据4单元格的HTML类", | ||
"type": "string" | |||
}, | }, | ||
" | "rowstyle4": { | ||
" | "label": "行4 CSS样式", | ||
"description": "应用到第4个内容行的CSS样式", | |||
"type": "line" | |||
}, | }, | ||
"header4": { | "header4": { | ||
"label": " | "label": "顶栏4", | ||
" | "description": "位于第4个内容行的顶栏", | ||
"type": "line" | |||
}, | }, | ||
"label4": { | "label4": { | ||
"label": " | "label": "标签4", | ||
" | "description": "位于第4个内容行的标签", | ||
"type": "line" | |||
}, | }, | ||
"data4": { | "data4": { | ||
"label": " | "label": "数据4", | ||
" | "description": "位于第4个内容行的数据", | ||
"type": "content" | |||
}, | }, | ||
" | "rowclass5": { | ||
"label": " | "label": "行5 HTML类", | ||
" | "description": "添加到第5个内容行的HTML类,编号可以继续延长", | ||
"type": "line" | |||
}, | }, | ||
" | "class5": { | ||
"label": " | "label": "数据5 HTML类", | ||
" | "description": "应用到数据5单元格的HTML类,编号可以继续延长", | ||
"type": "string" | |||
}, | }, | ||
" | "rowstyle5": { | ||
" | "label": "行5 CSS样式", | ||
"description": "应用到第5个内容行的CSS样式,编号可以继续延长", | |||
"type": "line" | |||
}, | }, | ||
"header5": { | "header5": { | ||
"label": " | "label": "顶栏5", | ||
" | "description": "位于第5个内容行的顶栏,编号可以继续延长", | ||
"type": "line" | |||
}, | }, | ||
"label5": { | "label5": { | ||
"label": " | "label": "标签5", | ||
" | "description": "位于第5个内容行的标签,编号可以继续延长", | ||
"type": "line" | |||
}, | }, | ||
"data5": { | "data5": { | ||
"label": " | "label": "数据5", | ||
" | "description": "位于第5个内容行的数据,编号可以继续延长", | ||
"type": "content" | |||
}, | }, | ||
" | "belowclass": { | ||
"label": " | "label": "底部单元格HTML类", | ||
" | "description": "添加到底部单元格的HTML类", | ||
"type": "line" | |||
}, | }, | ||
" | "belowstyle": { | ||
"label": " | "label": "底部单元格CSS样式", | ||
" | "description": "应用到底部单元格的CSS样式", | ||
"type": "line" | |||
" | |||
}, | }, | ||
"below": { | "below": { | ||
"label": "底部单元格", | "label": "底部单元格", | ||
"description": " | "description": "信息框最下方的单元格,一般用来添加脚注、另见和其他类似信息。" | ||
} | } | ||
}, | }, | ||
"format": "{{_\n | _ = _\n}} | "format": "{{_\n | _ = _\n}}", | ||
"description": "本模板用于构建信息框。通常本模板不应直接在条目中使用,但若需要,可在一次性情况中直接使用。" | |||
} | } | ||
</templatedata> | </templatedata> | ||
== 追踪分类 == | |||
* | * [[:Category:使用带有标题参数的嵌入式信息框模板的页面]] | ||
* | * [[:Category:使用无数据行信息框模板的条目]] | ||
* | * [[:Category:使用已忽略数据行信息框模板的页面]] | ||
== 另见 == | == 另见 == | ||
* [[Module:Infobox]] | * [[Module:Infobox]] — 本模板基于的Lua模块 | ||
* [[Module:Check for unknown parameters]] | * [[Module:Check for unknown parameters]] — 用于检测未知参数的模块 | ||
* {{tl|Navbox}}和{{tl|Sidebar}} | |||
* [[:Category:信息框模板]] — 所有信息框的总分类 | |||
* [[Module:InfoboxImage]] — 用于在信息框的任何位置放置图像 | |||
<includeonly> | |||
</ | {{Sandbox_other|| | ||
[[Category:信息框模板| ]] | |||
}} | |||
</includeonly> | |||
2022年12月23日 (五) 18:08的最新版本
{{Infobox}}是构建信息框的元模板,它用来构建一个像{{Infobox 一些主题}}的模板,比如{{Infobox_settlement}}。
此模板是信息框的元模板:它用来构建其他信息框模板。注意:此模板通常不应直接在条目中使用,但若需要,可在一次性情况中直接使用。wikipedia:Help:Infobox中包含关于信息框内容和设计的介绍。wikipedia:Wikipedia:Manual_of_Styles/Infoboxes中包含附加格式指南。参见Category:信息框模板查看已有的信息框模板。
使用
对于{{Infobox 一些主题}},经过简化的模板代码看起像这样:
{{Infobox
| name = {{{name|{{PAGENAME}}}}}
| image = {{{image|}}}
| caption1 = {{{caption|}}}
| label1 = 前名
| data1 = {{{former_names|}}}
| header2 = 一般信息
| label3 = 状态
| data3 = {{{status|}}}
... <!-- etc. -->
}}
参数
可选控制参数
- name
- 如果此参数存在,“查看·编辑·讨论”链接显示在信息框底部,链接指向此参数指定的页面。如果未在此参数中指定命名空间,则在链接前添加“
Template:”(模板)前缀。可使用{{subst:PAGENAME}};但这不太可能是你希望的,因为点击链接的用户会被导向模板页面/代码,而不是他们可能希望更改的条目中的信息框数据。 - child
- 详细信息参见嵌入一节。如果此参数设置为“yes”,这个子信息框应该含有标题,不含name参数。此参数默认为空。
- subbox
- 详细信息参见子盒一节。如果此参数设置为“yes”,这个子信息框应该含有标题,不含name参数。此参数默认为空。
- decat
- 如果此参数设置为“yes”,生成的信息框有问题,或不含有可见数据时,当前页面将不会被自动分类进维护分类中。此参数默认为空。
- autoheaders
- 如果此参数设置为任意非空值,则后面没有data字段的header会被隐藏。详细信息参见“在下方所有数据字段都为空时隐藏顶栏”一节。
内容参数
标题
有两种不同的在信息框中放置标题的方法。一种会将标题放置在信息框表格内最上面的单元格,另一种放置在表格上方。你可以同时使用这两种方法,或只使用其中一种,或者——尽管不推荐——都不用:
- title
- 放置在表格上方的标题文本(如果这是个子信息框,则作为整个表格内容的区域标题)
- above
- 放置在表格内最上面单元格的文本。
- subheadern
- 附加标题字段,显示在title和above之下,图像之上。
示例:
{{Infobox
| name = Infobox/doc
| title = 信息框上方的标题
| subheader = 信息框的子标题
| header = (信息框的其他部分)
}}
| 信息框的子标题 | |
{{Infobox
| name = Infobox/doc
| above = 信息框内最上方单元格的文本
| subheader = 信息框的子标题
| subheader2 = 信息框第2个子标题
| header = (信息框的其他部分)
}}
| 信息框的子标题 | |
| 信息框第2个子标题 | |
插图
- imagen
- 显示在模板顶部的图像。使用完整图像语法,例如
[[File:Example.png|200px|alt=示例替代文本]]。图像默认居中。参见wikipedia:WP:ALT获取关于替代文本的更多信息。 - captionn
- 图像下面的描述文本。
主要数据
- headern
- 在第n行作为顶栏的文本。
- labeln
- 在第n行作为标签的文本。
- datan
- 在第n行显示为数据的文本。
注意:在单行(比如第n行)中,不是所有参数组合都可用。|headern=会与对应的|datan=(以及|labeln=、|rowclassn=,见下)冲突,使得|datan=不会显示;缺少|datan=会隐藏对应的|labeln=。在单行中可用的组合有:
|classn=|headern=|rowclassn=|classn=|datan=|rowclassn=|labeln=|classn=|datan=
可在下方示例章节查看header4、label4和data4的显示情况。
编号范围
在顶栏和标签/数据行的编号中使用不连续编号可以在修改信息框时增加灵活性。之后如果需要插入新行,先前使用不连续编号的信息框就不用为已存在的所有参数重新编号了。例如:
| header3 = 区域 1 | label5 = 标签 A | data5 = 数据 A | label7 = 标签 C | data7 = 数据 C | header10 = 区域 2 | label12 = 标签 D | data12 = 数据 D
也可以自动重新编号参数名,使用wikipedia:User:Frietjes/infoboxgap.js或者wikipedia:Module:IncrementParams。
编号没有最大限制,但在两个编号之间最多只能相差50。
可选的数据字段
只有标签,没有数据的行不会显示。这样可以简单地创建选填的信息。要使一行可选,填写一个默认为空的数据参数就行,像这样:
| label5 = 人口
| data5 = {{{population|}}}
这样的话,当条目未提供人口(|population=)参数时,信息框的这一行就不会显示。
对于带有预格式化(除了数据之外还有其他内容)内容的复杂字段,在没有指定参数时它依然会显示。你可以把参数和预设内容都放进“#if”语句里,这样在没有指定参数时,预设内容也不会显示。比如下面的示例中的“#if”语句:“#if(如果):指定了mass参数|显示mass参数,后跟‘ kg’”:
| label6 = 质量
| data6 = {{ #if: {{{mass|}}} | {{{mass}}} kg }}
#if的更多信息可见于mw:Help:Extension:ParserFunctions##if和metawikimedia:ParserFunctions##if:。
在下方所有数据字段都为空时隐藏顶栏
也可以让顶栏只在其下方的某个或多个数据单元有内容时才显示。
考虑这种情况:
{{Infobox
| title = 示例:带或不带数据的顶栏
| headerstyle = background: lightgrey;
| header1 = 带有空区域的header1
| label2 = label2文本 | data2 =
| label3 = label3文本 | data3 =
| label4 = label4文本 | data4 =
| header5 = 带有下方数data的header5
| label6 = label6文本 | data6 = 一些值
}}
| 带有空区域的header1 | |
|---|---|
| 带有下方data的header5 | |
| label6 文本 | 一些值 |
如果你希望在|datan=没有值时隐藏顶栏,使用|autoheaders=y:
{{Infobox
| title = 示例:带或不带数据的顶栏
| autoheaders = y
| headerstyle = background: lightgrey;
| header1 = 带有空区域的header1
| label2 = label2文本 | data2 =
| label3 = label3文本 | data3 =
| label4 = label4文本 | data4 =
| header5 = 带有下方data的header5
| label6 = label6文本 | data6 = 一些值
}}
| 带有下方data的header5 | |
|---|---|
| label6文本 | 一些值 |
这样,header1会在data2、data3或data4中任意一个非空时显示。如果3个参数都为空,那么顶栏就不会显示,在到下一个可见内容之前也不会出现空行。
注意:如果数据含有空HTML元素,像|data=<span style="background: yellow;"></span>,那么这个数据会被视作非空(有数据)。
如果设置了|autoheader=y,但你不希望一些项触发顶栏,放置|headerX=。这会被当做空顶栏并分隔开它与后续项目。
{{Infobox
| title = 示例:带或不带数据的空顶栏
| autoheaders = y
| headerstyle = background: lightgrey;
| header1 = 带有空区域的header1
| label2 = label2文本 | data2 =
| label3 = label3文本 | data3 =
| label4 = label4文本 | data4 =
| header5 = _BLANK_
| label6 = label6文本 | data6 = 一些值,但不会触发header1或者显示header5
}}
| label6文本 | 一些值,但不会触发header1或者显示header5 |
|---|
信息框脚
- below
- 放置在底部单元格的文本。底部单元格用于放置脚注、另见和其他类似信息。
显示参数
斜体标题
通过传递italic title参数,带有信息框条目的标题可显示为斜体,符合WP:ITALICTITLE。
- 在信息框中传递
|italic title={{{italic title|}}}来启用斜体标题。 - 传递
|italic title={{{italic title|no}}}默认禁用斜体标题(特别是因为只有拉丁文字可以安全地以这种样式显示,而且可能需要斜体来区分外语和本地英语,而其他文字的斜体可能很难阅读),但可在一些情况下启用。 - 不传递此参数来禁用全部斜体标题。
模板样式
模板样式参数|templatestyles=、|child templatestyles=和|grandchild templatestyles=接收模板样式页的名称(例如Template:Example/styles.css),并转换为模板样式标签(<templatestyles src="Template:Example/styles.css" /> )。模板样式在样式化信息框时更为强力。
一些使用规则:
始终在|bodyclass=中添加这个信息框独有的的类,这样添加到一个信息框的样式就不会“泄露”到另一个信息框中。例如,Template:Infobox_settlement含有.infobox-settlement类,信息框模板样式的所有CSS选择器都需要匹配这个类。
这些标签以这个顺序加载:
- 核心模板样式(Module:Infobox/styles.css)
- 一般模板样式(
|templatestyles=) - 子模板样式(
|child templatestyles=) - 孙模板样式(
|grandchild templatestyles=)
因此,这些样式表可以“层叠”。
- templatestyles
- 为直接调用{{Infobox}}的模板或模块添加的模板样式。
- child templatestyles
- 在模板/模块调用的信息框已有
|templatestyles=时,为模板/模块添加额外模板样式。 - grandchild templatestyles
- 在模板/模块调用的信息框已有
|child templatestyles=时,为模板/模块添加额外模板样式。
模板样式参数使用示例
一个无需支持子模板的信息框(无论是它没有子模板还是不想要子模板):
{{Infobox
| title = {{{name|示例信息框}}}
| bodyclass = infobox-example
| templatestyles = Template:Infobox_example/styles.css
}}
一个需要支持子模板的信息框:
{{Infobox
| title = {{{name|示例信息框}}}
| bodyclass = infobox-example {{{class|}}}
| templatestyles = Template:Infobox_example/styles.css
| child templatestyles = {{{child templatestyles|}}}
}}
它的一个子信息框:
{{Infobox_example
| title = {{{name|示例子信息框}}}
| bodyclass = infobox-example-child
| child templatestyles = Template:Infobox_example_child/styles.css
}}
这样子信息框可以添加它独有的类和模板样式,叠起来了!
支持孙模板的方法是类似的,模板需要额外传递|grandchild templatestyles=参数,而子模板也需要传递|bodyclass=和|grandchild templatestyles=。
CSS样式
- bodystyle
- 应用到整个信息框表格
- titlestyle
- 仅应用到表格上方的标题。添加背景颜色通常是不明智的,因为文本会显示在消息框外。
- abovestyle
- 仅应用到信息框顶部单元格。默认样式有
font-size: 125%;因为此单元格通常用于标题。如果你希望将此单元格的文本改为正常大小,在abovestyle里包含“font-size: 100%”。 - subheaderstyle
- 应用到所有子标题单元格
- imagestyle
- 应用到图像所在的单元格,包括图像描述。在设置图像描述的文本属性时应使用captionstyle,而不是imagestyle,以防止未来图像描述移出此单元格。
- captionstyle
- 应用到图像描述文本。
- rowstylen
- 此参数插入到指定行的
style属性中。 - headerstyle
- 应用到所有顶栏单元格
- labelstyle
- 应用到所有标签单元格
- datastyle
- 应用到所有数据单元格
- belowstyle
- 仅应用到信息框底部单元格
HTML类和微格式
- bodyclass
- 此参数插入到信息框(即
<table class="infobox ...">…</table>)的class属性中。 - titleclass
- 此参数插入到信息框外部标题的
class属性中。 - aboveclass
- 此参数插入到信息框above单元格的
class属性中。 - subheaderrowclassn
- 此参数插入到子标题所在的整个表格行的
class属性中。 - subheaderclassn
- 此参数插入到信息框子标题的
class属性中。 - imagerowclassn
- 此参数插入到图像所在的整个表格行的
class属性中。 - imageclass
- 此参数插入到图像的
class属性中。 - rowclassn
- 此参数插入到指定行的
class属性中,包括label和data单元格。 - classn
- 此参数插入到指定行中data的
class属性中。如果没有data单元格就不会生效。 - belowclass
- 此参数插入到信息框below单元格的
class属性中。
此模板支持附加微格式信息。这是通过为不同data单元格添加“class”属性来实现的,不同的class属性可以指示相关数据单元格包含何种类型的信息。可以指定多个类名,使用空格分隔,其中一些类作为CSS选择器,附加相关样式,另一些用于微格式。
要标记一个信息框包含hCard信息,作为示例,添加下方参数:
| bodyclass = vcard
为于每行包含属于vcard一部分的data单元格,添加一个相应的class参数:
| class1 = fn | class2 = org | class3 = tel
…等等。通常用于显示信息框主题的“above”和“title”也可以添加类。
可在wikipedia:Wikipedia:WikiProject Microformats获取在wiki内添加微格式信息的进一步信息,访问微格式官方网站亦能获取更一般性的信息。
示例
注意,当定义了标签但相关的数据单元格为空时,那一行不会显示在信息框中;在一行中同时定义了顶栏、标签和数据时,只有顶栏会显示。也要注意,子标题(subheader)默认不像用于分隔主要数据区域的顶栏(header)那样显示为粗体,因为子标题的角色像顶部单元格(above)。
{{Infobox
| name = Infobox/doc
| bodystyle =
| titlestyle =
| abovestyle = background: #cfc;
| subheaderstyle =
| title = 测试信息框
| above = 顶部文本
| subheader = 图像上方的子标题
| subheader2 = 第2个子标题
| imagestyle =
| captionstyle =
| image = [[File:Example.png|200px|alt=示例替代文本]]
| caption = 显示在File:Example.png下方的描述
| headerstyle = background: #ccf;
| labelstyle = background: #ddf;
| datastyle =
| header1 = 独自定义的顶栏
| label1 =
| data1 =
| header2 =
| label2 = 独自定义的标签,不会显示,只有对应的数据存在时才会显示
| data2 =
| header3 =
| label3 =
| data3 = 独自定义的数据
| header4 = 三项均有定义(顶栏)
| label4 = 不会显示(因为与顶栏的编号相同)
| data4 = 不会显示(因为与顶栏的编号相同)
| header5 =
| label5 = 定义的标签和数据(标签)
| data5 = 定义的标签和数据(数据)
| belowstyle = background: #ddf;
| below = 底部文本
}}
| 顶部文本 | |
|---|---|
| 图像上方的子标题 | |
| 第2个子标题 | |
![]() 显示在File:Example.png下方的描述 | |
| 独自定义的顶栏 | |
| 独自定义的数据 | |
| 三项均有定义(顶栏) | |
| 定义的标签和数据(标签) | 定义的标签和数据(数据) |
| 底部文本 | |
这个示例中,|bodystyle=和|labelstyle=参数用来调整信息框宽度,并设定label一列的默认宽度:
{{Infobox
| name = Infobox/doc
| bodystyle = width: 20em;
| titlestyle =
| title = 测试信息框
| headerstyle =
| labelstyle = width: 33%;
| datastyle =
| header1 =
| label1 = 标签1
| data1 = 数据1
| header2 =
| label2 = 标签2
| data2 = 数据2
| header3 =
| label3 = 标签3
| data3 = 数据3
| header4 = 顶栏4
| label4 =
| data4 =
| header5 =
| label5 = 标签5
| data5 = 数据5: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
| belowstyle =
| below = 底部文本
}}
| 标签1 | 数据1 |
|---|---|
| 标签2 | 数据2 |
| 标签3 | 数据3 |
| 顶栏4 | |
| 标签5 | 数据5: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |
| 底部文本 | |
嵌入
信息框可以通过使用|child=参数嵌入到另一个信息框中。这一功能可用于创建模块化信息框,或者创建逻辑定义更好的区域。很久之前,为了创建有超过99行内容的信息框,需要使用嵌入功能,但现在单一信息框没有行数限制了。
{{Infobox
| title = 顶层标题
| data1 = {{Infobox | decat = yes | child = yes
| title = 第1个子部分
| label1 = 标签1.1
| data1 = 数据1.1
}}
| data2 = {{Infobox | decat = yes | child = yes
| title = 第2个子部分
| label1 = 标签2.1
| data1 = 数据2.1
}}
| belowstyle =
| below = 底部文本
}}
| 第1个子部分 | |
| 标签1.1 | 数据1.1 |
|---|---|
| 第2个子部分 | |
| 标签2.1 | 数据2.1 |
| 底部文本 | |
注意,上例中,子信息框放置在数据字段中,而非顶栏字段。除非特别指定,否则子信息框标题不会显示为粗体。如需让子部分标题显示为粗体,除了使用CSS外,也可以考虑使用下面的方法:
{{Infobox
| title = 顶层标题
| header1 = 第1个子部分
| data2 = {{Infobox | decat = yes | child = yes
| label1 = 标签1.1
| data1 = 数据1.1
}}
| header3 = 第2个子部分
| data4 = {{Infobox | decat = yes | child = yes
| label1 = 标签2.1
| data1 = 数据2.1
}}
| belowstyle =
| below = 底部文本
}}
| 第1个子部分 | |
|---|---|
| 标签1.1 | 数据1.1 |
| 第2个子部分 | |
| 标签2.1 | 数据2.1 |
| 底部文本 | |
在不使用|title=且不在嵌入的信息框前面添加任何文本的话,可能会在子信息框前生成一个空表格行,在视觉上添加间隙。空表格行可以用|rowstylen=display: none;来隐藏,将n替换为数据行的编号。
wikipedia:Wikipedia:WikiProject Infoboxes/embed包含一些链接,指向使用嵌入到其他信息框的信息框的条目。
子盒
另一种嵌入方法是使用|subbox=yes,这种方法移除信息框外部边框,但保留嵌入信息框的内部结构。这种方法的一个特点是子、父信息框不必含有相同的结构,标签和数据字段在两个信息框之间也不会对齐,因为他们的父表格不相同。
{{Infobox
| headerstyle = background-color: #eee;
| labelstyle = background-color: #eee;
| header1 = 主 1
| header2 = 主 2
| data3 = {{Infobox | subbox = yes
| headerstyle = background-color: #ccc;
| labelstyle = background-color: #ddd;
| header1 = 子 3-1
| header2 = 子 3-2
| label3 = 标签 3-3 | data3 = 数据 3-3
}}
| data4 = {{Infobox | subbox = yes
| labelstyle = background-color: #ccc;
| label1 = 标签 4-1 | data1 = 数据 4-1
}}
| label5 = 标签 5 | data5 = 数据 5
| header6 = 主 6
}}
| 主 1 | |||||||
|---|---|---|---|---|---|---|---|
| 主 2 | |||||||
| |||||||
| |||||||
| 标签 5 | 数据 5 | ||||||
| 主 6 | |||||||
相似的嵌入技术可以用在其他生成表格的模板的内容参数(例如{{Sidebar}}):
{{Sidebar
| navbar = off
| headingstyle = background-color: #eee;
| heading1 = 标题 1
| heading2 = 标题 2
| content3 = {{Infobox | subbox = yes
| headerstyle = background-color:#ccc;
| labelstyle = background-color:#ddd;
| header1 = 子 3-1
| header2 = 子 3-2
| label3 = 标签 3-3 | data3 = 数据 3-3
}}
| content4 = {{Infobox | subbox = yes
| labelstyle = background-color: #ccc;
| label1 = 标签 4-1 | data1 = 数据 4-1
}}
| heading5 = 标题 5
}}
包含每个子盒的父数据单元格的默认内边距依然可见,因此子盒比父盒略窄,并且父盒标准单元格之间的垂直间距比不同子盒单元格之间的垂直间距大。
在嵌入的不带点列表中控制换行
{{nbsp}}模板可以和{{wbr}}和{{nowrap}}一起用来控制嵌入在信息框中的不带点列表的换行(例如:wikipedia:Template:Infobox film中的参演人员列表)。要防止包装的长实体和其他实体之间混淆,参见Template:Wbr/doc#控制信息框中的换行获取详情。
完整空白语法
注意:行编号是无限的,下面只提供20个编号,因为使用更大编号的信息框相对比较少见,在需要时扩展编号就行。微格式“class”参数也省略掉了,因为它们不太常用。
{{Infobox
| name = {{subst:PAGENAME}}
| child = {{{child|}}}
| subbox = {{{subbox|}}}
| italic title = {{{italic title|no}}}
| templatestyles =
| child templatestyles =
| grandchild templatestyles =
| bodystyle =
| titlestyle =
| abovestyle =
| subheaderstyle =
| title =
| above =
| subheader =
| imagestyle =
| captionstyle =
| image =
| caption =
| image2 =
| caption2 =
| headerstyle =
| labelstyle =
| datastyle =
| header1 =
| label1 =
| data1 =
| header2 =
| label2 =
| data2 =
| header3 =
| label3 =
| data3 =
| header4 =
| label4 =
| data4 =
| header5 =
| label5 =
| data5 =
| header6 =
| label6 =
| data6 =
| header7 =
| label7 =
| data7 =
| header8 =
| label8 =
| data8 =
| header9 =
| label9 =
| data9 =
| header10 =
| label10 =
| data10 =
| header11 =
| label11 =
| data11 =
| header12 =
| label12 =
| data12 =
| header13 =
| label13 =
| data13 =
| header14 =
| label14 =
| data14 =
| header15 =
| label15 =
| data15 =
| header16 =
| label16 =
| data16 =
| header17 =
| label17 =
| data17 =
| header18 =
| label18 =
| data18 =
| header19 =
| label19 =
| data19 =
| header20 =
| label20 =
| data20 =
| belowstyle =
| below =
}}
移植到其他MediaWiki
{{Infobox}}依赖于mw:Extension:Scribunto和mw:Extension:TemplateStyles扩展,mw:Extension:ParserFunction扩展很可能也是必需的,所以目标MediaWiki需要安装这三个扩展。你需要复制以下页面:
- Template:Infobox — 主模板;
- Template:Infobox/doc — 可选的模板文档,应该也可以直接复制,但安装了mw:Extension:TemplateData扩展才能支持模板数据。
- Module:Infobox — 生成信息框的Lua模块;
- Module:Infobox/styles.css — 信息框CSS样式。
Lua模块也有自己的依赖项,全复制过去。
模板数据
本模板用于构建信息框。通常本模板不应直接在条目中使用,但若需要,可在一次性情况中直接使用。
| 参数 | 描述 | 类型 | 状态 | |
|---|---|---|---|---|
| 名称 | name | 信息框底部“查看·编辑·讨论”链接指向模板的名称,如果不指定命名空间,会在链接前添加“Template:”(模板)前缀。
| 单行文本 | 可选 |
| 子盒式 | child | 模板是否以子盒格式显示 | 布尔 | 可选 |
| 嵌入式 | embed | 模板是否以嵌入格式显示 | 布尔 | 可选 |
| 禁用分类 | decat | 模板是否会禁用维护分类 | 布尔 | 可选 |
| 斜体标题 | italic title | 启用后页面标题会变为斜体 | 布尔 | 弃用 |
| 自动顶栏 | autoheaders | 启用本功能的话,下方没有非空数据字段的顶栏都会被隐藏。 | 布尔 | 可选 |
| 模板样式 | templatestyles | 信息框需要加载的模板样式
| 单行文本 | 可选 |
| 子模板样式 | child templatestyles | 子模板加载的模板样式,重复示例中的值就行。使用此功能也需要为bodyclass参数的最后一个类后面添加{{{bodyclass|}}},例如“bodyclass = infobox-example {{{bodyclass|}}}”。
| 单行文本 | 可选 |
| 孙模板样式 | grandchild templatestyles | 孙模板加载的模板样式,重复示例中的值就行。详情参见模板文档的“模板样式”一节。
| 单行文本 | 可选 |
| 整体HTML类 | bodyclass | 添加到信息框整体的HTML类
| 单行文本 | 可选 |
| 整体CSS样式 | bodystyle | 应用到信息框整体的CSS样式
| 字符串 | 可选 |
| 标题HTML类 | titleclass | 添加到信息框外部标题的HTML类 | 单行文本 | 可选 |
| 顶部单元格HTML类 | aboveclass | 添加到顶部单元格的HTML类 | 字符串 | 可选 |
| 子标题2表格行HTML类 | subheaderrowclass2 | 添加到子标题2所处表格行的HTML类,编号可以继续延长 | 单行文本 | 可选 |
| 子标题2 HTML类 | subheaderclass2 | 添加到子标题2单元格的HTML类,编号可以继续延长 | 单行文本 | 可选 |
| 标题CSS样式 | titlestyle | 应用到信息框外部标题的CSS样式 | 字符串 | 可选 |
| 顶部单元格CSS样式 | abovestyle | 应用到顶部单元格的CSS样式 | 单行文本 | 可选 |
| 子标题CSS样式 | subheaderstyle | 应用到所有子标题的CSS样式 | 未知 | 可选 |
| 标题 | title | 信息框外部标题 | 内容 | 可选 |
| 顶部单元格 | above | 信息框最上方的单元格(内部标题) | 内容 | 可选 |
| 子标题1 | subheader subheader1 | 信息框的第1个子标题 | 内容 | 可选 |
| 子标题1表格行HTML类 | subheaderrowclass subheaderrowclass1 | 添加到子标题1所处表格行的HTML类 | 单行文本 | 可选 |
| 子标题1 HTML类 | subheaderclass subheaderclass1 | 添加到子标题1单元格的HTML类 | 单行文本 | 可选 |
| 子标题2 | subheader2 | 信息框的第2个子标题,编号可以继续延长 | 内容 | 可选 |
| 图像1表格行HTML类 | imagerowclass imagerowclass1 | 添加到图像1所处表格行的HTML类 | 单行文本 | 可选 |
| 图像2表格行HTML类 | imagerowclass2 | 添加到图像2所处表格行的HTML类 | 单行文本 | 可选 |
| 图像HTML类 | imageclass | 添加到所有图像单元格的HTML类 | 单行文本 | 可选 |
| 图像CSS样式 | imagestyle | 应用到所有图像单元格的CSS样式 | 单行文本 | 可选 |
| 图像描述CSS样式 | captionstyle | 应用到所有图像描述文本的CSS样式 | 单行文本 | 可选 |
| 图像1 | image image1 | 第1张图像,信息框图像显示在子标题下。图像使用完整wikitext图像语法。
| 单行文本 | 可选 |
| 图像描述1 | caption caption1 | 图像1的描述文本 | 内容 | 可选 |
| 图像2 | image2 | 第2张图像,编号可以继续延长 | 单行文本 | 可选 |
| 图像描述2 | caption2 | 图像2的描述文本,编号可以继续延长 | 内容 | 可选 |
| 顶栏CSS样式 | headerstyle | 应用到所有顶栏单元格的CSS样式 | 单行文本 | 可选 |
| 标签CSS样式 | labelstyle | 应用到所有标签单元格的CSS样式 | 单行文本 | 可选 |
| 数据CSS样式 | datastyle | 应用到所有数据单元格的CSS样式 | 单行文本 | 可选 |
| 行1 HTML类 | rowclass1 | 添加到第1个内容行的HTML类 | 单行文本 | 可选 |
| 数据1 HTML类 | class1 | 应用到数据1单元格的HTML类 | 字符串 | 可选 |
| 行1 CSS样式 | rowstyle1 | 应用到第1个内容行的CSS样式 | 单行文本 | 可选 |
| 顶栏1 | header1 | 位于第1个内容行的顶栏。顶栏居中显示,占用一整行的空间。 | 单行文本 | 可选 |
| 标签1 | label1 | 位于第1个内容行的标签。标签显示在信息框左侧,如果对应的数据没有内容,就不会显示。当同一行中同时存在顶栏,标签也不会显示。 | 单行文本 | 可选 |
| 数据1 | data1 | 位于第1个内容行的数据。当对应标签存在时,数据显示在信息框右侧,对应标签不存在时,居中显示,占用一整行的空间。当同一行中同时存在顶栏时,数据不会显示。 | 内容 | 可选 |
| 行2 HTML类 | rowclass2 | 添加到第2个内容行的HTML类 | 单行文本 | 可选 |
| 数据2 HTML类 | class2 | 应用到数据2单元格的HTML类 | 字符串 | 可选 |
| 行2 CSS样式 | rowstyle2 | 应用到第2个内容行的CSS样式 | 单行文本 | 可选 |
| 顶栏2 | header2 | 位于第2个内容行的顶栏 | 单行文本 | 可选 |
| 标签2 | label2 | 位于第2个内容行的标签 | 单行文本 | 可选 |
| 数据2 | data2 | 位于第2个内容行的数据 | 内容 | 可选 |
| 行3 HTML类 | rowclass3 | 添加到第3个内容行的HTML类 | 单行文本 | 可选 |
| 数据3 HTML类 | class3 | 应用到数据3单元格的HTML类 | 字符串 | 可选 |
| 行3 CSS样式 | rowstyle3 | 应用到第3个内容行的CSS样式 | 单行文本 | 可选 |
| 顶栏3 | header3 | 位于第3个内容行的顶栏 | 单行文本 | 可选 |
| 标签3 | label3 | 位于第3个内容行的标签 | 单行文本 | 可选 |
| 数据3 | data3 | 位于第3个内容行的数据 | 内容 | 可选 |
| 行4 HTML类 | rowclass4 | 添加到第4个内容行的HTML类 | 单行文本 | 可选 |
| 数据4 HTML类 | class4 | 应用到数据4单元格的HTML类 | 字符串 | 可选 |
| 行4 CSS样式 | rowstyle4 | 应用到第4个内容行的CSS样式 | 单行文本 | 可选 |
| 顶栏4 | header4 | 位于第4个内容行的顶栏 | 单行文本 | 可选 |
| 标签4 | label4 | 位于第4个内容行的标签 | 单行文本 | 可选 |
| 数据4 | data4 | 位于第4个内容行的数据 | 内容 | 可选 |
| 行5 HTML类 | rowclass5 | 添加到第5个内容行的HTML类,编号可以继续延长 | 单行文本 | 可选 |
| 数据5 HTML类 | class5 | 应用到数据5单元格的HTML类,编号可以继续延长 | 字符串 | 可选 |
| 行5 CSS样式 | rowstyle5 | 应用到第5个内容行的CSS样式,编号可以继续延长 | 单行文本 | 可选 |
| 顶栏5 | header5 | 位于第5个内容行的顶栏,编号可以继续延长 | 单行文本 | 可选 |
| 标签5 | label5 | 位于第5个内容行的标签,编号可以继续延长 | 单行文本 | 可选 |
| 数据5 | data5 | 位于第5个内容行的数据,编号可以继续延长 | 内容 | 可选 |
| 底部单元格HTML类 | belowclass | 添加到底部单元格的HTML类 | 单行文本 | 可选 |
| 底部单元格CSS样式 | belowstyle | 应用到底部单元格的CSS样式 | 单行文本 | 可选 |
| 底部单元格 | below | 信息框最下方的单元格,一般用来添加脚注、另见和其他类似信息。 | 未知 | 可选 |
追踪分类
另见
- Module:Infobox — 本模板基于的Lua模块
- Module:Check for unknown parameters — 用于检测未知参数的模块
- {{Navbox}}和{{Sidebar}}
- Category:信息框模板 — 所有信息框的总分类
- Module:InfoboxImage — 用于在信息框的任何位置放置图像
