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. Learn by doing. 

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 for the most part, 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 increased and improved use of CSS behind the scenes.

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, math, or anything else that could normally work with an, 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 has a few part templates, but manually adds a centered row holding a table. 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, it's made entirely of centered rows. So if it doesn't quite work for a certain infobox, it can be skipped, its behavior can be imitated in a way that does work.

Keep in mind
Standard wikitext rules apply, such as wrapping the above inner table in an  will require the  s within it to be escaped. HTML and tag-based parsing used inside a row template will require being run through the  function, as with a Tabber below:

If for whatever reason the part templates do not work for your purposes but you still need infobox rows, remember to use the classes that the templates defines to keep consistent styling in your infobox.

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.