Template:DisplayBox: Difference between revisions
Microcosms (talk | contribs) m Testing better thin-screen sizing. Tag: Reverted |
Microcosms (talk | contribs) m Can't seem to dynamically resize images so this is not possible. Undo revision 421 by Microcosms (talk) Tag: Undo |
||
Line 143: | Line 143: | ||
<div style="background-color:#f9f9f9;border:1.5px solid #e9e9e9;border-radius:10px;"> |
<div style="background-color:#f9f9f9;border:1.5px solid #e9e9e9;border-radius:10px;"> |
||
<div style="margin-bottom:10px"> |
<div style="margin-bottom:10px"> |
||
{{#if:{{{image|}}}|<div style=" |
{{#if:{{{image|}}}|<div style="width:250px;margin:10px 10px 0 10px;background-color:#eeeeee;border-radius:10px;">[[File:{{{image}}}|250px]]</div>|}} |
||
{{#if:{{{caption|}}}|<div style=" |
{{#if:{{{caption|}}}|<div style="width:250px;padding:3px 0 3px 0;margin:10px 10px 0 10px;text-align:center;background-color:#eeeeee;border-radius:10px;"><i>{{{caption}}}</i></div>|}}</div>{{#if:{{{image|}}}|<hr style="margin:0 5px 0 5px;color:#f9f9f9;">|}} |
||
<table style=" |
<table style="width:250px !important;margin:10px !important;border-collapse:revert;"> |
||
{{#if:{{{field0|}}}| |
{{#if:{{{field0|}}}| |
||
{{#if:{{{entry0|}}}| |
{{#if:{{{entry0|}}}| |
Revision as of 12:47, 13 July 2024
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
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: