Community Central
Community Central
(+ Note about parameters)
(Fix)
Tag: sourceedit
 
(4 intermediate revisions by the same user not shown)
Line 15: Line 15:
   
 
== Plan the infobox ==
 
== Plan the infobox ==
Let's make a plan! Think about what you want your infobox to look like, and decide about visibility.
+
Let's make a plan! Think about what you want your infobox to look like, and decide about visibility. It might help to write down your plan on a piece of paper, or type it somewhere.
   
 
If I wanted to make a template "[[:Template:Infobox Wolf3D level]]" for the game ''Wolfenstein 3D'', it might follow this format:
 
If I wanted to make a template "[[:Template:Infobox Wolf3D level]]" for the game ''Wolfenstein 3D'', it might follow this format:
Line 28: Line 28:
 
** Number of chalices (default: "0")
 
** Number of chalices (default: "0")
 
** Number of chests (default: "0")
 
** Number of chests (default: "0")
* Heading: Other stats
+
* Heading: "Other stats"
 
** Par time (default: hidden)
 
** Par time (default: hidden)
 
** Song that plays (default: hidden)
 
** Song that plays (default: hidden)
Line 63: Line 63:
 
Let's take a look at the standard code of [[:Template:Infobox]]. Remember that this is the ''default'' code, and not necessarily the code that will be seen on your infobox. I've colored it myself for clarity - you're not likely to see this kind of coloring when you actually edit.
 
Let's take a look at the standard code of [[:Template:Infobox]]. Remember that this is the ''default'' code, and not necessarily the code that will be seen on your infobox. I've colored it myself for clarity - you're not likely to see this kind of coloring when you actually edit.
   
  +
{| class="wikitable mw-collapsible mw-collapsed" style="margin-left:auto;margin-right:auto; line-height:14px;"
{{Thisismyrofl-infobox-explain}}
 
  +
|-
  +
! colspan="2" | An explanation of the code of the infobox
  +
|-
  +
| colspan="2" | Note that linebreaks have been added, sparingly, for readability on this page.
  +
|-
  +
! The code
  +
! An explanation
  +
|- style="font-size:10px;font-family:monospace;"
  +
|
  +
<poem>
  +
<span style="color:purple;"><<nowiki/>onlyinclude>{| class="wikia-infobox"
  +
  +
|-
  +
! class="wikia-infobox-header" colspan="2" | {<nowiki/>{<nowiki/>{title|'<nowiki/>'Unknown'<nowiki/>'}}}</span>
  +
  +
<span style="color:orange;">|-
  +
{<nowiki/>{#if: {<nowiki/>{<nowiki/>{image|}}} |
  +
{<nowiki/>{!}} class="wikia-infobox-image" colspan="2" {<nowiki/>{!}}
  +
[[File:{<nowiki/>{<nowiki/>{image}}}|{<nowiki/>{<nowiki/>{imagewidth|210}}}px|{<nowiki/>{<nowiki/>{imagecaption|}}}]]
  +
| }}
  +
  +
|-
  +
{<nowiki/>{#if: {<nowiki/>{<nowiki/>{imagecaption|}}} |
  +
{<nowiki/>{!}} class="wikia-infobox-caption" colspan="2" {<nowiki/>{!}} {<nowiki/>{<nowiki/>{imagecaption}}}
  +
| }}</span>
  +
  +
<span style="color:green;">|-
  +
! colspan="2" |
  +
<<nowiki/>div class="wikia-infobox-section-header">Some attributes<<nowiki/>/div></span>
  +
  +
<span style="color:red;">|-
  +
! First
  +
| {<nowiki/>{<nowiki/>{first|'<nowiki/>'Unknown'<nowiki/>'}}}
  +
  +
|-
  +
! Second
  +
| {<nowiki/>{<nowiki/>{second|'<nowiki/>'Unknown'<nowiki/>'}}}
  +
  +
|-
  +
! Third
  +
| {<nowiki/>{<nowiki/>{third|'<nowiki/>'Unknown'<nowiki/>'}}}</span>
  +
  +
<span style="color:green;">|-
  +
! colspan="2" |
  +
<<nowiki/>div class="wikia-infobox-section-header">Other attributes<<nowiki/>/div></span>
  +
  +
<span style="color:blue;">|-
  +
{<nowiki/>{#if: {<nowiki/>{<nowiki/>{fourth|}}} |
  +
! Fourth
  +
{<nowiki/>{!}} {<nowiki/>{<nowiki/>{fourth}}}
  +
| }}
  +
  +
|-
  +
{<nowiki/>{#if: {<nowiki/>{<nowiki/>{fifth|}}} |
  +
! Fifth
  +
{<nowiki/>{!}} {<nowiki/>{<nowiki/>{fifth}}}
  +
| }}
  +
  +
|-
  +
{<nowiki/>{#if: {<nowiki/>{<nowiki/>{sixth|}}} |
  +
! Sixth
  +
{<nowiki/>{!}} {<nowiki/>{<nowiki/>{sixth}}}
  +
| }}</span>
  +
  +
<span style="color:purple;">|- style="font-size:0; line-height:0;"
  +
! style="width:50%; padding:0" |
  +
! style="width:50%; padding:0" |
  +
  +
|}<<nowiki/>/onlyinclude><<nowiki/>noinclude><<nowiki/>br style="clear:both;"/>
  +
{<nowiki/>{documentation}}<<nowiki/>/noinclude></span>
  +
</poem>
  +
|
  +
<poem>
  +
<span style="color:purple;">Opens the infobox. Every time you see |<nowiki/>-
  +
it means a new row. This line begins with !
  +
which means it's a heading. This heading is
  +
the top of the infobox: if unspecified it says "Unknown".</span>
  +
<span style="color:grey;">NOTE: whitespace (linebreaks) don't affect the code.</span>
  +
<span style="color:orange;">
  +
Here we present the image to be used in the article.
  +
The #if statement checks if the article defined
  +
{{{image}}}. If not, the entire field is omitted.
  +
  +
  +
  +
Here we present the small caption under the image. As above,
  +
all is omitted if {{{imagecaption}}} isn't defined.
  +
</span>
  +
  +
<span style="color:green;">
  +
The first two-column header. It says "Some attributes".
  +
Feel free to change "Some attributes" to your needs!</span>
  +
  +
<span style="color:red;">Each of these is a field in the infobox.
  +
By default, they say "First", "Second", "Third".
  +
If undefined, they say "Unknown".
  +
  +
You can change the fields. Just change
  +
"First" or "Second", and also change
  +
{{{first and {{{second to whatever fits.
  +
  +
You can change the default text from 'Unknown' too.
  +
Remember to change documentation:
  +
| first =
  +
</span>
  +
<span style="color:green;">
  +
The second two-column header.
  +
Again, feel free to change it, or remove entirely!</span>
  +
  +
<span style="color:blue;">These are 3 infobox fields, but they're different
  +
from the previous (red) fields. These rows
  +
will be totally hidden, if "fourth", "fifth", etc
  +
are undefined. The red parameters would have displayed
  +
under similar circumstances, only to say "Unknown".
  +
  +
  +
Decide what kind is more suited to your needs.
  +
If you want to use this format but adapt it,
  +
you will have to change several bits of the code.
  +
  +
  +
You will have to change the following to meet your needs:
  +
1. {{<nowiki />{sixth|}}} on this line
  +
2. "Sixth" on this line
  +
3. {{{sixth}}} on this line
  +
4. | sixth = in the documentation</span>
  +
  +
<span style="color:purple;">|<nowiki/>} closes the table, thus closing the infobox.
  +
It's best not to mess with this.
  +
  +
  +
Now the table and infobox is closed.
  +
This last template displays documentation.</span>
  +
</poem>
  +
|}
   
 
=== Visibility ===
 
=== Visibility ===

Latest revision as of 01:13, 7 December 2015

150px-1330470.png Other blogs by Thisismyrofl
Infoboxes
Suggestions


Template:Infobox Wolf3D levelHey! This is Thisismyrofl, an admin here on Community Central. I wanted to see if I could explain how to use the new style of Template:Infobox (new as in September 2012). On your left, you see a basic infobox made in the new infobox format. We'll learn how to make an infobox of our own to meet our specific needs!

I'm referring here to the default styles, that is, those that were on the Starter Pages Wiki's Template:Infobox page. Since every newly created wiki, at the time of its creation, is given a copy of every page and template on Starter Pages Wiki, that means that there are thousands of wikis that came with the old style, and thousands founded after September 2012 that came with the new style.

Plan the infobox

Let's make a plan! Think about what you want your infobox to look like, and decide about visibility. It might help to write down your plan on a piece of paper, or type it somewhere.

If I wanted to make a template "Template:Infobox Wolf3D level" for the game Wolfenstein 3D, it might follow this format:

Template:Infobox Wolf3D level
* Title
* Image
* Image caption
*  Heading: "Treasure"
** Number of crosses	(default: "0")
** Number of chalices	(default: "0")
** Number of chests	(default: "0")
* Heading: "Other stats"
** Par time		(default: hidden)
** Song that plays	(default: hidden)
** Number of secrets	(default: hidden)

If a row is left empty when the template is called, we must decide whether it should give a default value (such as "Unknown") or be hidden (that is, the row won't show up at all). Jump to the section #Visibility for more information. Mark on your plan how you want each row to be treated.

Default syntax

Let's also make the default syntax for the new template! This can be copied into the template's documentation. It should look something like this.

{{Infobox Wolf3D level
| title        = 
| image        = 
| imagewidth   = 
| imagecaption = 
| crosses      = 
| chalices     = 
| chests       = 
| par          = 
| song         = 
| secrets      = 
}}

This is what will be pasted into an article and then filled out to make a fully-fledged infobox appear on the article! But before it works, you need to customize the page "Infobox Wolf3D level" on your wiki. Try not to be excessive in naming the parameters: lowercase, typed as one word is sufficient, because it doesn't affect the appearance of the infobox anyway.

Now that we've planned it out, let's customize our infobox.

Understanding the code

Let's take a look at the standard code of Template:Infobox. Remember that this is the default code, and not necessarily the code that will be seen on your infobox. I've colored it myself for clarity - you're not likely to see this kind of coloring when you actually edit.

An explanation of the code of the infobox
Note that linebreaks have been added, sparingly, for readability on this page.
The code An explanation

<onlyinclude>{| class="wikia-infobox"
 
|-
! class="wikia-infobox-header" colspan="2" | {{{title|''Unknown''}}}

 
|-
{{#if: {{{image|}}} |
{{!}} class="wikia-infobox-image" colspan="2" {{!}}
[[File:{{{image}}}|{{{imagewidth|210}}}px|{{{imagecaption|}}}]]
| }}
 
|-
{{#if: {{{imagecaption|}}} |
{{!}} class="wikia-infobox-caption" colspan="2" {{!}} {{{imagecaption}}}
| }}

 
|-
! colspan="2" |
<div class="wikia-infobox-section-header">Some attributes</div>

 
|-
! First
| {{{first|''Unknown''}}}
 
|-
! Second
| {{{second|''Unknown''}}}
 
|-
! Third
| {{{third|''Unknown''}}}

 
|-
! colspan="2" |
<div class="wikia-infobox-section-header">Other attributes</div>

 
|-
{{#if: {{{fourth|}}} |
! Fourth
{{!}} {{{fourth}}}
| }}
 
|-
{{#if: {{{fifth|}}} |
! Fifth
{{!}} {{{fifth}}}
| }}
 
|-
{{#if: {{{sixth|}}} |
! Sixth
{{!}} {{{sixth}}}
| }}

 
|- style="font-size:0; line-height:0;"
! style="width:50%; padding:0" |
! style="width:50%; padding:0" |
 
|}</onlyinclude><noinclude><br style="clear:both;"/>
{{documentation}}</noinclude>

Opens the infobox. Every time you see |-
it means a new row. This line begins with !
which means it's a heading. This heading is
the top of the infobox: if unspecified it says "Unknown".

NOTE: whitespace (linebreaks) don't affect the code.

Here we present the image to be used in the article.
The #if statement checks if the article defined
{{{image}}}. If not, the entire field is omitted.
 
 
 
Here we present the small caption under the image. As above,
all is omitted if {{{imagecaption}}} isn't defined.

 

The first two-column header. It says "Some attributes".
Feel free to change "Some attributes" to your needs!

 
Each of these is a field in the infobox.
By default, they say "First", "Second", "Third".
If undefined, they say "Unknown".
 
You can change the fields. Just change
"First" or "Second", and also change
{{{first and {{{second to whatever fits.
 
You can change the default text from 'Unknown' too.
Remember to change documentation:
| first =


The second two-column header.
Again, feel free to change it, or remove entirely!

 
These are 3 infobox fields, but they're different
from the previous (red) fields. These rows
will be totally hidden, if "fourth", "fifth", etc
are undefined. The red parameters would have displayed
under similar circumstances, only to say "Unknown".
 
 
Decide what kind is more suited to your needs.
If you want to use this format but adapt it,
you will have to change several bits of the code.
 
 
You will have to change the following to meet your needs:
1. {{{sixth|}}} on this line
2. "Sixth" on this line
3. {{{sixth}}} on this line
4. | sixth = in the documentation

 
|} closes the table, thus closing the infobox.
It's best not to mess with this.
 
 
Now the table and infobox is closed.
This last template displays documentation.

Visibility

There are two types of infobox rows: those with default values and those which are hidden if no value is given. By default, the first three have default values, and the fourth, fifth, and sixth are hidden.

Below, two infoboxes: on the right, I have filled in the template entirely, but on the left I have left all six fields blank. Because they're blank, the first three return the default value "Unknown". The fourth, fifth, and sixth are differently coded: when no value is specified, they do not appear at all. Keep this difference in mind.


Edit your infobox!

DON'T CHANGE THE PAGE Template:Infobox! You're supposed to leave it unchanged and edit other infobox templates, which you can copy from Template:Infobox.

I'll assume that at this point, you already have an infobox or infobox template at the location "Infobox Wolf3D level" on your wiki[footnotes 1], or whatever you've decided to name it. If you haven't, take a look at my other blog: User blog:Thisismyrofl/Creating a new-style infobox.

Any part of this can be modified, but look at the {{{3}}}, {{{3}}}, and {{{3}}} parts. Those are the important parts we need to work with. Until your abilities with templates have improved, it's best to leave the {{{3}}} and {{{3}}} parts alone.

Editing headings

Click here to see how I did it!

By default, the infobox has two heading snippets, highlighted in green in my above code. Their default texts are "some attributes" and "other attributes".

|-

! colspan="2" | <div class="wikia-infobox-section-header">Some attributes

The default texts aren't really specific enough for a lot of wikis. Just change the text "Some attributes" and "Other attributes" (highlighted here in yellow) to your liking! You can leave the rest of the code intact.

As always, you can remove either or both of the headings if you want (just delete any code that looks like the above heading) or add headings (just paste in a copy of the above code).

Editing rows with defaults

Click here to see how I did it!

By default, the infobox has six rows, the first three of which have the property that when a parameter is undefined, the row still shows - showing instead a default text.

|-
! First
| {{{first|''Unknown''}}}

|-
! Second
| {{{second|''Unknown''}}}

|-
! Third
| {{{third|''Unknown''}}}

Each of these three obvious snippets is a row, but the default headings ("first", "second", "third") don't work for a lot of people. So we can feel free to change them! I've highlighted the bits of code you'd edit.

  1. Change the header text (here highlighted in cyan) to read whatever you want to appear on the left side of the infobox row.
  2. Change the parameter name (here highlighted in green) to display the parameter name you decided on in your default syntax earlier. For example, my first parameter was to be "crosses", so I'd type {{{crosses|...}}} where the ellipsis ("...") stands for the default text - see the next step.
  3. Change the default text (highlighted in yellow) if you want. The default action is that an unspecified parameter will display the code ''Unknown'' which returns an italicized: "Unknown". You can change the default text to whatever you want, and format it with italics, without italics, or otherwise. For example, my default number of crosses was to be "0". So, combined with the parameter name from earlier, I'd type {{{crosses|0}}}
  4. I've highlighted and explained how to edit the "First" row, but you can follow the same steps for the second and third.

As always, remember that you can remove one, two, or all three of the above snippets of code in order to use fewer rows with defaults (perhaps if you want all your rows to be hidden), or you can add your own.

Editing rows that hide

Click here to see how I did it!

By default, the infobox has six rows, the fourth, fifth, and sixth of which have the property that when a parameter is undefined, the row does not appear at all. Contrast with the above behavior.

|-
{{#if: {{{fourth|}}} |
! Fourth
{{!}} {{{fourth}}}
| }}

|-
{{#if: {{{fifth|}}} |
! Fifth
{{!}} {{{fifth}}}
| }}

|-
{{#if: {{{sixth|}}} |
! Sixth
{{!}} {{{sixth}}}
| }}

Each of these three obvious snippets is a row, but the default headings ("fourth", "fifth", "sixth") don't work for a lot of people. So we can feel free to change them! I've highlighted the bits of code you'd edit.

  1. Change the header text (here highlighted in cyan) to read whatever you want to appear on the left side of the infobox row.
  2. Change the parameter name (here highlighted in green) to display the parameter name you decided on in your default syntax earlier. For example, my first parameter which I wanted to be hidden was to be "par", so I'd type {{{par|}}} in the first spot and {{{par}}} in the second. (It makes a difference!)
  3. I've highlighted and explained how to edit the "Fourth" row, but you can follow the same steps for "Fifth" and "Sixth".

As always, remember that you can remove one, two, or all three of the above snippets of code in order to use fewer rows with default action to hide, or you can add your own.

We're mostly done!

Now you can save the page! Enjoy your new infobox! Paste your default syntax into an article and fill it in. The infobox I made looks like the one on the right. Super pretty!

Finishing touches

The above steps are the important part, which is why I had you save the page. There's a few other things that we can do, but your template will function fine without them.

Default title

Click here to see how I did it!

The |title= parameter controls what appears at the top of the infobox, in the fourth row of the code.

! class="wikia-infobox-header" colspan="2" | {{{title|''Unknown''}}}

By default, you have to fill it in, otherwise your infobox will have a nasty italicized "Unknown" at the top. A smarter behavior can be brought about by switching in a {{PAGENAME}} magic word:

! class="wikia-infobox-header" colspan="2" | {{{title|{{PAGENAME}}}}}

Now, if the title is left blank, it'll default to the name of the page. You might still have to edit the |title= parameter on some pages.

Documentation

Templates are kinda complicated, so it's best to have a little snippet of information on how to use it at the bottom of the template. You'll notice that at the bottom of the default template code, there's a {{Documentation}} template call. This calls Template:Documentation, which varies from wiki to wiki, but in any case, it will transclude the page located at Template:Your template/doc.

Here's a wise layout for your new template's documentation:

== Default syntax==
Paste this into the page, then fill it in, to use the template.
<pre>
{{Infobox Wolf3D level
| title         = 
| image         = 
| imagewidth    = 
| imagecaption  = 
| crosses       = 
| chalices      = 
| chests        = 
| par           = 
| song          = 
| secrets       = 
}}
</pre>

<noinclude>[[Category:Template documentation]]</noinclude>

Paste that to Template:Infobox Wolf3D level/doc (substituting in the name of your infobox) on your wiki[footnotes 1] Remember, though, that you need to substitute in your default syntax for what I've pasted here.

Be bold!

I've only outlined the basics of editing infoboxes. Feel free to be bold and try editing them further! If you mess up, you can always undo the edits from the page's history.

Notes

  1. 1.0 1.1 A number of times, this page refers to pages on your wiki, such as "Template:Infobox on your wiki". I don't know what your wiki is, so I can't directly link to it, but if you're having trouble finding the correct page, just click the link to go to the equivalent page on Community Central, then edit the URL so that community.wikia.com is substituted with your wiki's URL: for example wolfenstein.wikia.com.

See also