Template:Infobox: Difference between revisions

From Wayne's Dusty Box of Words
ll>Primefac
(Undid revision 855063393 by Jdlrobson (talk) rather problematic change mentioned on talk page, reverting until it can be sorted)
 
m (1 revision imported)
 
(No difference)

Latest revision as of 12:18, 8 February 2022

This template supports the addition of microformat information. This is done by adding "class" attributes to various data cells, indicating what kind of information is contained within. Multiple class names may be specified, separated by spaces, some of them being used as selectors for custom styling according to a project policy or to the skin selected in user preferences, others being used for microformats.

To flag an infobox as containing hCard information, for example, add the following parameter:

 | bodyclass = vcard

And for each row containing a data cell that's part of the vcard, add a corresponding class parameter:

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

...and so forth. "above" and "title" can also be given classes, since these are usually used to display the name of the subject of the infobox.

See Wikipedia:WikiProject Microformats for more information on adding microformat information to Wikipedia, and microformat for more information on microformats in general.

Examples

Notice how the row doesn't appear in the displayed infobox when a label is defined without an accompanying data cell, and how all of them are displayed when a header is defined on the same row as a data cell. Also notice that subheaders are not bold by default like the headers used to split the main data section, because this role is meant to be for the above cell :

Test Infobox
Above text
Subheader above image
Second subheader
Example alt text
Caption displayed below File:Example-serious.jpg
Header defined alone
Data defined alone
All three defined (header, label, data, all with same number)
Label and data defined (label)Label and data defined (data)
Below text

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }} <syntaxhighlight lang="Sass" style="overflow:auto" highlight="15"> Lua error in Module:Navbar at line 58: Invalid title {{subst:PAGENAME}}.{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }}

</syntaxhighlight>

For this example, the |{{SAFESUBST:#if:bodystyle|bodystyle=}} and |{{SAFESUBST:#if:labelstyle|labelstyle=}} parameters are used to adjust the infobox width and define a default width for the column of labels:

Test Infobox
Label 1Data 1
Label 2Data 2
Label 3Data 3
Header 4
Label 5Data 5: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Below text

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }} <syntaxhighlight lang="sass" highlight="3,9" style="overflow: auto"> Lua error in Module:Navbar at line 58: Invalid title {{subst:PAGENAME}}.{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }}

</syntaxhighlight>

Embedding

One infobox template can be embedded into another using the |{{SAFESUBST:#if:child|child=}} parameter. This feature can be used to create a modular infobox, or to create better-defined logical sections. Long ago, it was necessary to use embedding in order to create infoboxes with more than 99 rows; but nowadays there's no limit to the number of rows that can be defined in a single instance of {{infobox}}.

Top level title
First subsection
Label 1.1Data 1.1

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Second subsection
Label 2.1Data 2.1

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Below text

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }}

{{Infobox
 | title = Top level title
 | data1 = {{Infobox | decat = yes | child = yes
    | title = First subsection
    | label1= Label 1.1
    | data1 = Data 1.1
   }}
 | data2 = {{Infobox | decat = yes | child = yes
  |title = Second subsection
  | label1= Label 2.1
  | data1 = Data 2.1
  }}
 | belowstyle = 
 | below = Below text
}}

Note, in the examples above, the child infobox is placed in a data field, not a header field. Notice that the section subheadings are not in bold font if bolding is not explicitly specified. To obtain bold section headings, place the child infobox in a header field (but not in a label field because it would not be displayed!), either using

Top level title
First subsection
Label 1.1Data 1.1

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Second subsection
Label 2.1Data 2.1

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Below text

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }}

{{Infobox
 | title = Top level title
 | header1 = {{Infobox | decat = yes | child = yes
    | title = First subsection
    | label1= Label 1.1
    | data1 = Data 1.1
   }}
 | header2 = {{Infobox | decat = yes | child = yes
    | title = Second subsection
    | label1= Label 2.1
    | data1 = Data 2.1
   }}
 | belowstyle = 
 | below = Below text
}}

or,

Top level title
First subsection
Label 1.1Data 1.1

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Second subsection
Label 2.1Data 2.1

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Below text

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }}

{{Infobox
 | title = Top level title
 | header1 = First subsection
   {{Infobox | decat = yes | child = yes
    | label1 = Label 1.1
    |   data1 = Data 1.1
   }}
 | header2 = Second subsection
   {{Infobox | decat = yes | child = yes
    | label1 = Label 2.1
    |  data1 = Data 2.1
   }}
 | belowstyle = 
 | below = Below text
}}

Note that omitting the |{{SAFESUBST:#if:title|title=}} parameter, and not including any text preceding the embedded infobox, may result in spurious blank table rows, creating gaps in the visual presentation. The garbage output can be suppressed using |{{SAFESUBST:#if:rowstyleN|rowstyleN=}}display: none, replacing N with the data/header number.

Wikipedia:WikiProject Infoboxes/embed includes some links to Wikipedia articles which include infoboxes embedded within other infoboxes.

Subboxes

An alternative method for embedding is to use |{{SAFESUBST:#if:subbox|subbox=}}yes, which removes the outer border from the infobox, but preserves the interior structure. One feature of this approach is that the parent and child boxes need not have the same structure, and the label and data fields are not aligned between the parent and child boxes because they are not in the same parent table.

Main 1
Main 2
Sub 3-1
Sub 3-2
Label 3-3Data 3-3
{{#switch:
 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Label 4-1Data 4-1
{{#switch:
 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Label 5Data 5
Main 6

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }} <syntaxhighlight lang="sass" style="overflow:auto">

Main 1
Main 2
Sub 3-1
Sub 3-2
Label 3-3Data 3-3
{{#switch:
 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Label 4-1Data 4-1
{{#switch:
 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default =

}}
Label 5Data 5
Main 6

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#ifeq:Infobox|Infobox||{{#ifeq:Infobox|Infobox|[[Category:Infobox templates|Template:Remove first word]]}}}} | other | #default = }}

</syntaxhighlight>

Similar embedding techniques may be used within content parameters of some other templates generating tables (such as Sidebar) :

<syntaxhighlight lang="sass" style="overflow:auto">

</syntaxhighlight>

Note that the default padding of the parent data cell containing each subbox is still visible, so the subboxes are slightly narrower than the parent box and there's a higher vertical spacing between standard cells of the parent box than between cells of distinct subboxes.

Controlling line-breaking in embedded bulletless lists

Template {{[[{{#if:|{{{SISTER}}}Template|Template}}:nbsp|nbsp]]{{#if:||{{{2}}}}}{{#if:||{{{3}}}}}{{#if:||{{{4}}}}}{{#if:||{{{5}}}}}{{#if:||{{{6}}}}}{{#if:||{{{7}}}}}{{#if:||...}}}} may be used with {{[[{{#if:|{{{SISTER}}}Template|Template}}:wbr|wbr]]{{#if:||{{{2}}}}}{{#if:||{{{3}}}}}{{#if:||{{{4}}}}}{{#if:||{{{5}}}}}{{#if:||{{{6}}}}}{{#if:||{{{7}}}}}{{#if:||...}}}} and {{[[{{#if:|{{{SISTER}}}Template|Template}}:nowrap|nowrap]]{{#if:||{{{2}}}}}{{#if:||{{{3}}}}}{{#if:||{{{4}}}}}{{#if:||{{{5}}}}}{{#if:||{{{6}}}}}{{#if:||{{{7}}}}}{{#if:||...}}}} to control line-breaking in bulletless lists embedded in infoboxes (e.g. cast list in {{[[{{#if:|{{{SISTER}}}Template|Template}}:Infobox film|Infobox film]]{{#if:||{{{2}}}}}{{#if:||{{{3}}}}}{{#if:||{{{4}}}}}{{#if:||{{{5}}}}}{{#if:||{{{6}}}}}{{#if:||{{{7}}}}}{{#if:||...}}}}), to prevent wrapped long entries from being confused with multiple entries. See Template:Wbr/doc#Controlling line-breaking in infoboxes for details.

Full blank syntax

(Note: there is no limit to the number of possible rows; only 20 are given below since infoboxes larger than that will be relatively rare. Just extend the numbering as needed. The microformat "class" parameters are also omitted as they are not commonly used.)

{{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          = 
}}

Help:Infobox/user style

Porting to other MediaWikis

The infobox template requires the Scribunto extension. WikiProject Transwiki has a version of this template that has been modified to work on other MediaWikis.

TemplateData

{{#if:|{{#switch:
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|C|c}}lick here] to see a monthly parameter usage report for {{#if:|[[Template:]]|this template}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}

|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report] for {{#if:|[[Template:]]|Template:Infobox}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|#default=[1]{{#ifeq:{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}} }}|This is the {{#if:|TemplateData|TemplateData}} for this template used by TemplateWizard, VisualEditor and other tools. {{#switch:

|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|C|c}}lick here] to see a monthly parameter usage report for {{#if:|[[Template:]]|this template}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}

|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3A%7C%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report] for {{#if:|[[Template:]]|Template:Infobox}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}}.

|#default=[2]{{#ifeq:{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:|its|this}} TemplateData}} }}}}

TemplateData for Infobox

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Template|Template
   | template
   | other
   }}
 }}

| template = {{#if:{{#ifeq:Infobox|sandbox|1}}{{#ifeq:Infobox|doc|1}}||

}} | other | #default = }} <templatedata> {

   "description": "This template is intended as a meta template, a template used for constructing other templates. In general, it is not meant for use directly in an article but can be used on a one-off basis if required.",

"format": "Template:\n\n", "params": { "title": { "label": "Title", "description": "Title displayed above the infobox", "type": "string", "suggested": true } }, "paramOrder": [ "title" ] } </templatedata>


Tracking categories

See also

{{#if:{{#ifeq:Infobox|sandbox|1}}{{#ifeq:Infobox|doc|1}}|| }}

{{#if:|

[[Category:Template documentation pages{{#translation:}}]] }}