Template:Infobox example

This wiki makes use of infobox parts to build its infoboxes. These parts are templates for commonly repeated parts and functionality within an infobox, designed to make building infoboxes easier. A functioning, reusable infobox using these parts can be found at Template:Infobox.

In a nutshell
tl;dr, copy and paste this to a new Template page to build a simple infobox, replacing a, b, and c with whatever you want, and adding more b/c rows as needed. 

Basics
There are 6 main infobox parts:, , , , , and (referred to in this guide as start, header, section, row, centered row, and end). Start and end must be placed at the start and end of your infobox template. Header is typically placed right after the start, with parameters,   and. A section typically follows the header, then some rows, and then the end. This is how infoboxes are normally made, the only difference is we're trimming down the code to make it easier to read and use. For example, observe the following code block:  The above code block is how infoboxes normally look on the inside. Lots of repeated code and it's not really pretty to look at. Observe now the following code block: 

The above two code blocks are functionally the same, but in the second one we've outsourced a lot of the repeated code to the part templates that we're calling instead and making more use of CSS.

The main point of confusion is with what appears to be duplicate inputs in the rows, such as. The first parameter is of course the row title, and the second is the value of that row. This weird third parameter is a test value. This is covered in more detail in the documentation for Template:Infobox row, but in short, the third parameter is run through an  test, and if the result is false the entire row is hidden. In the code above, this means that every row is testing its value, and if it would be empty, the row is hidden. Anything could be tested here, such as other values, namespace tests, or anything else that can be evaluated as an empty string, but testing the row's own value is the most common use case. This third parameter is optional.

Advanced
For full documentation of each part template, see their respective documentation pages.

Modularity
Notice in the above code block that between the header and section there is an  inserted. Because these part templates are modular, they can be placed in any order, and additional wikicode can be inserted between, and in some cases, inside them as needed. So an infobox could have something like: 


 * colspan=2 |
 * colspan=2 |

This will make a centered row holding a table, but hide the row if  is not given. Please be careful when doing this however, so as not to add something that would be wider than the infobox.

Header is actually itself made up of the other parts, with the exception of the main title and the use of, so if it doesn't quite work for a certain infobox, its behavior can be remade for that box.

Replacement values
comes with an optional fourth parameter. This fourth parameter builds off of the third. To reiterate the third, test-value, it hides the row if its value is an empty string. The fourth parameter, else-value, will cause the row to not be hidden if test-value is empty, but it will instead replace the row's value with this else-value. For example, if we have, this will create a row in the infobox titled "Health", with a value of  , but if   is undefined, a ? will be used in its place.

This test-value and else-value behavior is shared by centered row and section, but instead of being parameters 3 and 4, they are 2 and 3, respectively, since those templates otherwise only have one input instead of two.

Infobox classes
comes with an optional first parameter, which adds classes to the infobox. Say for example you are making an infobox for spells, and you want the infobox to have different colors depending on the spell's element. You would do. If element=Fire, the infobox now has, and you can then add the appropriate CSS rules to the site CSS (if you do not have permission to modify site CSS, consult the wiki's manager and/or admins).

Spacing
can be used to add a 0.5em space between rows. Its first parameter is a test-value, and will not display if given an empty string. This is useful for adding space after an image or other object, but hiding it if the object isn't displayed.

Template:Infobox example is intended to serve as an instruction manual for infobox parts and is not supposed to be used on pages itself.