Template:DisplayBox

From Amplicity


A metatemplate for creating Infobox-like boxes for displaying field-entry pairs.

Usage

1. Create a new template page

This page should ideally be named in the format Template:DisplayBox <type> e.g. Template:DisplayBox User.

2. Construct the template

Ensure only the template code is wrapped between <includeonly> tags. As such, the page should contain at least:

<includeonly>
{{DisplayBox
|image   = {{{image|}}}
|caption = {{{caption|}}}
|field0  = <fill this in>
|entry0  = <fill this in with {{{field_name|}}}>
}}
</includeonly>

Note that the name of the template being called is DisplayBox, not Template:DisplayBox <type> (which is instead what is called when the new template is being called).

3. Add template fields

Relations between different components of the templates derived from Template:DisplayBox

The "field<n>", "entry<n>" pairs describes rows of the table (n takes values between 0 and 29 inclusive) in the format:

Contents of field<n> Contents of entry<n>

Creating "field<n>", "entry<n>" pairs for use in the new template involves naming the data field (i.e. what's in the left cell in the above table), and then naming the template field (i.e. what's on the left hand side of the equals sign when the new template is actually being used) to use as input (see the figure to the right for a visual representation of these relations). For example, in the source code of Template:DisplayBox User:

{{DisplayBox
...
|field0 = Username
|entry0 = {{{username|}}}
...
}}

...becomes:

{{DisplayBox User
...
|username = <insert username here>
...
}}

...when Template:DisplayBox User gets called (e.g. in a user's page), to produce the table row:

Username <insert username here>

Repeat this as many times as desired (as long as n is less than or equal to 29).

4. Add documentation

Wrap anything that doesn't form part of the template code within <noinclude> tags.

<noinclude>
This doesn't form part of the template
</noinclude>
<includeonly>{{DisplayBox
...
</includeonly>
}}

Make sure there's no newline between the <includeonly> tag and {{DisplayBox start.

Full Example

From Template:DisplayBox User, with the <noinclude> stuff removed. On the Template:DisplayBox User page:

<includeonly>
{{DisplayBox
|image  = {{{image|}}}
|caption = {{{caption|}}}
|field0 = Username
|entry0 = {{{username|}}}
|field1 = Nicknames
|entry1 = {{{nicknames|}}}
|field2 = Join Date
|entry2 = {{{join_date|}}}
|field3 = Gender
|entry3 = {{{gender|}}}
|field4 = Nationality
|entry4 = {{{nationality|}}}
|field5 = Occupation
|entry5 = {{{occupation|}}}
}}
</includeonly>

Which produces the ready-to-use template {{DisplayBox User ... }}:

{{DisplayBox User
|username    = 
|nicknames   = 
|image       =
|caption     = 
|join_date   = 
|gender      = 
|nationality = 
|occupation  = 
}}

Direct Call Example (can be ignored - included for testing only)

{{DisplayBox
|image = Apples.png
|caption = Apples
|field0 = Field the first
|entry0 = Entry the first
|field1 = Field the second
|entry1 = 
|field2 = Field the third
|entry2 = Entry the third
|field3 = Field the fourth
|entry3 = Entry the fourth
|field4 = Field the fifth
|entry4 = Entry the fifth
}}

Produces:

Apples

Field the first Entry the first
Field the third Entry the third
Field the fourth Entry the fourth
Field the fifth Entry the fifth