Template:Infobox example

From Official Temtem Wiki
Jump to navigation Jump to search
Template-info.png Documentation

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[edit]

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.

{{Infobox start}}
{{Infobox header
| name = {{{name|}}}
| image = {{{image|}}}
| description = {{{description|}}}
}}
{{Infobox section|a}}
{{Infobox row|b|{{{b|}}}}}
{{Infobox row|c|{{{c|}}}}}
{{Infobox end}}

Basics[edit]

There are 6 main infobox parts: {{Infobox start}}, {{Infobox header}}, {{Infobox section}}, {{Infobox row}}, {{Infobox centered row}}, and {{Infobox end}} (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 name, image and description. 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:

{| class="infoboxtable"
|-
! colspan="2" class="infoboxname" |  "{{{name}}}"
|-
{{#if: {{{image|}}} | ! colspan="2" {{!}} [[File:{{{image}}}|250x250px]] | {{#ifeq: {{NAMESPACE}} | Template | | [[Category:Infoboxes lacking images]]}} }}
|-
! colspan="2" class="infoboxdetails" | Details 
|-
{{#if: {{{race|}}} | {{!}} width=80 {{!}} <div>Race</div> {{!!}} {{{race}}} }}
|-
{{#if: {{{location|}}} | {{!}} <div>Location(s)</div> {{!!}} {{{location}}} }}
|-
{{#if: {{{source|}}} | {{!}} <div>Source</div> {{!!}} {{{source}}} }}
|-
{{#if: {{{reward|}}} | {{!}} <div>Reward</div> {{!!}} {{{reward}}} }}
|-
{{#if: {{{related|}}} | {{!}} <div>Related</div> {{!!}} {{{related}}} }}
|-
{{#if: {{{ID|}}} | {{!}} <div>ID</div> {{!!}} {{{ID}}} }}
|}

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:

{{Infobox start}}
{{Infobox header
| name = {{{name|}}}
| image = {{{image|}}}
| size = 250x250px
}}
{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{{image|}}}||[[Category:Infoboxes lacking images]]}}}}
{{Infobox section|Details}}
{{Infobox row|Race|{{{race|}}}|{{{race|}}}}}
{{Infobox row|Location(s)|{{{location|}}}|{{{location}}}}}
{{Infobox row|Source|{{{source|}}}|{{{source|}}}}}
{{Infobox row|Reward|{{{reward|}}}|{{{reward|}}}}}
{{Infobox row|Related|{{{related|}}}|{{{related|}}}}}
{{Infobox row|ID|{{{ID|}}}|{{{ID|}}}}}
{{Infobox end}}

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 {{Infobox row|Source|{{{source|}}}|{{{source|}}}}}. 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 {{#if}} 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 {{#if}}, but testing the row's own value is the most common use case. This third parameter is optional.

Advanced[edit]

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

Modularity[edit]

Notice in the above code block that between the header and section there is an {{#if}} 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:

{{Infobox start}}
{{Infobox section|Harvesting efficiency}}
{{Infobox row|Type|Gatherer}}
|-
| colspan=2 |
{| class="wikitable" style="width:100%"
! Creature !! Count !! Efficiency
|-
| {{{creature1|}}} || {{{count1|}}} || {{{efficiency1|}}}
|-
| {{{creature2|}}} || {{{count2|}}} || {{{efficiency2|}}}
|}
{{Infobox end}}

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 {{Infobox spacer}}, 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[edit]

Standard wikitext rules apply, such as wrapping the above inner table in an {{#if 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 {{#tag: function, as with a Tabber below:

{{infobox centered row|
{{#tag:tabber|
{{!}}-{{!}}
 {{{image1Title|Image 1}}}=
[[File:{{{image|}}}{{!}}{{{size|128x128px}}}]]
{{!}}-{{!}}
 {{{image2Title|Image 2}}}=
[[File:{{{image2|}}}{{!}}{{{size|128x128px}}}]]
{{#if:{{{image3|}}}|
{{!}}-{{!}}
 {{{image3Title|Image 3}}}=
[[File:{{{image3|}}}{{!}}{{{size|128x128px}}}]]
}} }}
|[[File:{{{image|}}}{{!}}{{{size|128x128px}}}]]
}}

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[edit]

{{Infobox row}} 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 {{Infobox row|Health|{{{health|}}}|{{health|}}}?}}, this will create a row in the infobox titled "Health", with a value of {{{health|}}}, but if {{{health|}}} 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[edit]

{{Infobox start}} 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 {{Infobox start|{{{element|}}}}}. If element=Fire, the infobox now has class="infobox Fire", 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[edit]

{{Infobox spacer}} 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.