Template:Infobox/doc

From NeuroWiki
Jump to navigation Jump to search

This template uses Module:Infobox, this script is written in Lua.
For more details, please refer to Wikipedia:Lua and Extension:Scribunto.

This template serves as a meta-template for a series of "Infobox" templates, meaning it is used to build other templates. It is generally not recommended to use this template directly in articles, but it can be used in specific "one-off" situations if necessary. See Help:Infobox for further methods to create general infoboxes.

Usage

This template is similar in usage to {{navbox}}, but there are some differences. Each line in the table can either be a header or a pair of label and data, or it can just be a single data cell. Each line can only have one state, with priority: if you define a line as both a header and a label/data pair, the label/data pair definition will be ignored.

Numbering

For ease of future changes to the infobox format, the numbering of header and label/data lines does not need to follow a strict order like 1, 2, 3, etc. You can leave gaps in the numbering to avoid renumbering all subsequent lines when adding new ones.

Header and label/data lines must not be repeated; for example, you cannot use both header1 and label1/data1 at the same time. Use header1, label2/data2 instead (as an example).

If you wish to renumber a large number of lines (such as when adding a new label requires incrementing all subsequent label numbers), consider using Module:IncrementParams.

Parameters

"View/Discuss/Edit/History" Links

name
The "View/Discuss/Edit/History" links need to point to the name of the template page (name). You can use {{subst:PAGENAME}}. If this parameter is not filled, the "View/Discuss/Edit/History" links will not display.

Title

Text outside the infobox title
(rest of the infobox)
Text inside the infobox title
(rest of the infobox)


There are two ways to add a title to an infobox. One is to place the title outside the infobox, and the other is to place it inside. You can choose either one based on your needs, use both, or even none at all (though we do not recommend the latter).

title
Text for the title outside the infobox table top.
above
Text for the title inside the infobox table top cell.

Optional

subheader
A subtitle below the above. Subheader2 is the second subtitle.
image
An image displayed at the top of the template. Use full image syntax, such as [[File:example.png|200px]]. It is recommended to use Module:InfoboxImage to insert images. By default, images are centered.


In the Chinese Wikipedia, an Infobox can use up to 4 image parameters: overimage (top), image (=image1), image2, image3, differing from the English Wikipedia Infobox which provides only image (=image1), image2.

caption
Caption text below the image.


Overcaption, caption (=caption1), caption2, caption3 correspond to the above 4 image parameters.

header(n)
Fill in the 'header' text for the nth line.
label(n)
Fill in the 'label' text for the nth line.
data(n)
Fill in the 'data' text for the nth line.
below
Text in the bottom cell of the infobox table, often used for notes, see also, and similar information.

Optional CSS Styles

bodystyle
Applies to the entire infobox table.
titlestyle
Applies to the title outside the infobox table. Background color is not recommended here as the text is outside the infobox.
abovestyle
Applies to the top cell inside the infobox table. Default style is "<syntaxhighlight lang="css" inline>font-size:large;</syntaxhighlight>" (large font size), as this cell is often used as a title. If you want normal font size, include "<syntaxhighlight lang="css" inline>font-size:medium;</syntaxhighlight>" in the content for that cell.
imagestyle
Applies to the image cell of the infobox including caption text. For compatibility and future changes, use captionstyle for caption text properties instead of imagestyle.
captionstyle
Applies to image caption text.
headerstyle
Applies to all header cells.
header(n)style
Applies to the nth header cell.
labelstyle
Applies to all label cells. To avoid label text wrapping, include "<syntaxhighlight lang="css" inline>white-space:nowrap;</syntaxhighlight>". Or use "min-width: 4em;".
label(n)style
Applies to the nth label cell.
datastyle
Applies to all data cells.
data(n)style
Applies to the nth data cell.
belowstyle
Applies to the bottom cell.

Microformats

bodyclass
This parameter affects the class of the whole infobox.
imageclass
This parameter affects the class of the image.
class(n)
This parameter affects the class of a specific line's data cell. Has no effect if there is no data cell in the infobox.
titleclass
This parameter affects the class of the infobox's external title.
aboveclass
This parameter affects the class of the infobox's internal title.

By defining class names for each data cell, this template can support microformats information; the class names are defined according to standards and can indicate information types to machines. For example, if an infobox uses the hCard microformat, to mark this microformat within the infobox, fill in the following parameters:

|bodyclass = vcard

And for each line containing data required by the vcard, add the corresponding class parameter:

|class1 = fn
|class2 = org
|class3 = tel

etc. The "above" and "title" used to display the infobox's subject can also specify classes.

For more information on adding microformat information on Wikipedia, visit Wikipedia:Microformats and the microformats.org website for more general information.

Optional Table Fields

If a line in the table has only a label and no data, that line will not display. This allows editors to create lines with optional content. To make a line optional, include a parameter with an empty default field:

|label5 = Population
|data5  = {{{population|}}}

Thus, if the "population" parameter is not defined in the article, that line in the infobox will not display.

If a line in the table is filled with preset formatted content (i.e., content other than parameters) and you wish to make it optional, you can achieve this with an "#if" statement. When the parameter is empty, all content will not be displayed. For example, in the following example, "#if" checks if the "mass" parameter is not empty, and if so, displays it with the suffix "kg":

|label6 = Mass
|data6  = {{#if:{{{mass|}}} |{{{mass}}} kg}}

For more on using #if, see Help:Template syntax#if.

If you want a header to display only when one or more data cells below it have content, the following example guides you on how to achieve that:

{{Infobox
|name        = {{subst:PAGENAME}}
|title       = Optional Header Use Case
|autoheaders = y
|header1     = Optional Header
|label2      = Item One
|data2       = {{{item_one|}}}
|label3      = Item Two
|data3       = {{{item_two|}}}
|label4      = Item Three
|data4       = {{{item_three|}}}
}}

Thus, "header1" will only display if one of the parameters "item_one," "item_two," or "item_three" is filled. If none of these parameters are defined, the header will not display.

Previously, implementing this feature required nesting lengthy "#if" syntax, but now you just need to set |autoheaders=y.

Examples

{{Infobox
|name         = Infobox
|bodystyle    = 
|title        = Test Infobox
|titlestyle   = 
|image        = [[File:No_image.svg|200px]]
|imagestyle   = 
|caption      = Caption for example.png
|captionstyle = 
|headerstyle  = background:#ccf;
|labelstyle   = background:#ddf;
|datastyle    = 

|header1 = Custom Header
|label1  = 
|data1   = 
|header2 = 
|label2  = Custom Label
|data2   = 
|header3 =
|label3  = 
|data3   = Custom Data
|header4 = All Three Defined (Header)
|label4  = All Three Defined (Label) — Error: Will not display due to header set
|data4   = All Three Defined (Data) — Error: Will not display due to header set
|header5 =
|label5  = Label and Data Defined (Label)
|data5   = Label and Data Defined (Data)

|belowstyle = background:#ddf;
|below = Below Text
}}
Test Infobox
Caption for example.png
Custom Header
Custom Data
All Three Defined (Header)
Label and Data Defined (Label)Label and Data Defined (Data)
Below Text

Note that when a label is defined independently without a data cell, that line does not appear in the infobox; and when a header is defined along with label/data in the same line, the header takes precedence.

In the example below, "bodystyle = width:20em;" and "labelstyle = width:33%;" are defined.

Test Infobox
Label 1Data 1
Label 2Data 2
Label 3Data 3
Header 4
Label 5Data 5: Gibberish.
Below Text


Complete Template

(Note: This template can handle up to 80 table lines simultaneously, and general infobox templates usually only use the first 20 lines of parameters, so the remaining 60 lines of parameters are omitted here. Use as needed by analogy. The "class" parameter for microformats is also omitted as it is not often used; please add it when needed.)

{{Infobox
| name               = {{subst:PAGENAME}}
| child              = {{{child|}}}
| subbox             = {{{subbox|}}}
| italic title       = {{{italic title|no}}}
| 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             = 
| belowstyle         = 
| below              = 
}}

See Also