Difference between revisions of "Template:Infobox/Doc"

From Temple of the White Rat
Jump to navigation Jump to search
Line 11: Line 11:
     ...
     ...
   <tr>
   <tr>
       <td class="infobox-data-title">...</td>
       <td class="ibfobox-data-title">...</td>
       <td class="infobox-data">...</td>
       <td class="ibfobox-data">...</td>
   </tr>
   </tr>
     ...
     ...
Line 40: Line 40:
* In the code it looks like this: <code><nowiki>{{#if: {{{title|}}}|{{{title|}}}|{{PAGENAME}}}}</nowiki></code>
* In the code it looks like this: <code><nowiki>{{#if: {{{title|}}}|{{{title|}}}|{{PAGENAME}}}}</nowiki></code>
** the use of <code>#if:</code> [[mw:Help:Extension:ParserFunctions|parser function]] means that parameter is optional and won't work if it's not filled
** the use of <code>#if:</code> [[mw:Help:Extension:ParserFunctions|parser function]] means that parameter is optional and won't work if it's not filled
** <code><nowiki>{{PAGENAME}}</nowiki></code> [[mw:Help:Magic words|magic word]] in the function means that by default template uses title of the page it's used on
** <code><nowiki>{{PAGENAME}}</nowiki></code> [[mw:Help:Magic words|magic word]] in the function means that by default the template uses title of the page it's used on


<code>file</code> - for an image file
<code>file</code> - for an image file
* In the code: <code><nowiki>{{#if: {{{file|}}}|<tr><td  colspan="2">[[File:{{{file|}}}{{!}}250px{{!}}center]]</td></tr>}}</nowiki></code>
* In the code: <code><nowiki>{{#if: {{{file|}}}|<tr><td  colspan="2">[[File:{{{file|}}}{{!}}250px{{!}}center]]</td></tr>}}</nowiki></code>
** <code>#if:</code> once again means it's optional, but in this case there is no default value, in other words, if no image is provided there will nothing; otherwise function adds new row in the table, which will contain image
** <code>#if:</code> once again means it's optional, but in this case there is no default value, in other words, if no image is provided there will nothing; otherwise function adds new row in the table, which will contain image
** [[mw:Help:Images|wiki mark up for images]] sets how image will be formatted inside infobox, in this case it has fixed width - <code>250px</code>, and align - <code>center</code>, but these values can be set up as another pair of parameters
** [[mw:Help:Images|wiki mark up for images]] sets how image will be formatted inside the infobox, in this case it has fixed width - <code>250px</code>, and align - <code>center</code>, but these values can be set up as another pair of parameters
** only name of the file with format is needed
** only name of the file with format is needed


Line 59: Line 59:
<code>prm1</code> - second data parameter, with "Parameter 2" title
<code>prm1</code> - second data parameter, with "Parameter 2" title
* In the code:<br><code><nowiki>{{#if: {{{prm2|}}}|<tr>
* In the code:<br><code><nowiki>{{#if: {{{prm2|}}}|<tr>
           <td class="infobox-data-title">Parameter 2</td>
           <td class="ibfobox-data-title">Parameter 2</td>
           <td class="infobox-data">{{{prm2}}}</td>
           <td class="ibfobox-data">{{{prm2}}}</td>
     </tr>}}</nowiki></code>
     </tr>}}</nowiki></code>
** <code>#if:</code> again means it's optional, but if filled it will add a row with two columns
** <code>#if:</code> again means it's optional, but if filled it will add a row with two columns
Line 69: Line 69:
* and several '''classes'''
* and several '''classes'''
** <code>infobox</code> for entire table - this wiki already has such class in [[MediaWiki:Common.css|Common.css]] page; most notably it puts the box into right side of the page and gives it background color and border
** <code>infobox</code> for entire table - this wiki already has such class in [[MediaWiki:Common.css|Common.css]] page; most notably it puts the box into right side of the page and gives it background color and border
** <code>infobox-data-title</code> - for column with data titles; will be a custom class in [[Template:Classic infobox/styles.css]] page - for educational purposes it will brighter than usual Wikipedia style
** <code>ibfobox-data-title</code> - for column with data titles; will be a custom class in [[Template:Classic infobox/styles.css]] page - for educational purposes it will brighter than usual Wikipedia style
** <code>infobox-data</code> - for second column, with data values; same as previous
** <code>ibfobox-data</code> - for second column, with data values; same as previous


===Categories===
===Categories===
Line 82: Line 82:
To use infobox on another page, this code must be used:
To use infobox on another page, this code must be used:
<pre>
<pre>
{{infobox
{{Classic infobox
|title =
|title =
|file =  
|file =  
Line 100: Line 100:
Code of filled up example:
Code of filled up example:
<pre>
<pre>
{{infobox
{{Classic infobox
|title = This is the title
|title = This is the title
|file = De Alice's Abenteuer im Wunderland Carroll pic 15.jpg
|file = De Alice's Abenteuer im Wunderland Carroll pic 15.jpg

Revision as of 07:05, 29 January 2022

This is an example of infobox template - a simple infobox coded as table. It was copied from https://template.miraheze.org/wiki/Template:Classic_infobox

Overview

Table

Infobox is a table. There is two ways to build tables on wiki spaces - using HTML mark up (tags) or using wiki mark up.

Here HTML tags were used:

<table class="infobox">
   <tr><td  colspan="2" style="text-align: center; font-size:140%;">...</td></tr>
     ...
   <tr>
       <td class="ibfobox-data-title">...</td>
       <td class="ibfobox-data">...</td>
   </tr>
     ...
</table>

Wiki mark up variant:

{| class="infobox"
|colspan="2" style="text-align: center; font-size:140%;"| ...
|-
...
|class="ibfobox-data-title"| ...
|...
|-
...
|}

For more information about wiki tables see: Help:Tables.

Parameters

In all templates parameters are placed in the code with triple curly braces: {{{|}}}. Parameters can have a code name - {{{<codename>|}}}, which can be placed in any order on actual page, as long as code names are written correctly. Without code names numbers should be used instead - {{{1|}}}, and on another page template will look at the order of values filled in it.

This example infobox has 5 parameters:

title - used to force custom text in a header of infobox

  • In the code it looks like this: {{#if: {{{title|}}}|{{{title|}}}|{{PAGENAME}}}}
    • the use of #if: parser function means that parameter is optional and won't work if it's not filled
    • {{PAGENAME}} magic word in the function means that by default the template uses title of the page it's used on

file - for an image file

  • In the code: {{#if: {{{file|}}}|<tr><td colspan="2">[[File:{{{file|}}}{{!}}250px{{!}}center]]</td></tr>}}
    • #if: once again means it's optional, but in this case there is no default value, in other words, if no image is provided there will nothing; otherwise function adds new row in the table, which will contain image
    • wiki mark up for images sets how image will be formatted inside the infobox, in this case it has fixed width - 250px, and align - center, but these values can be set up as another pair of parameters
    • only name of the file with format is needed

caption - caption under image

  • In the code: {{#if: {{{caption|}}}|<tr><td colspan="2" style="text-align: center;">''{{{caption|}}}''</td></tr>}}
    • #if: - optional, without default value, otherwise adds new row in the table
    • there text formatting: style="text-align: center;" - for align, and ''...'' - to give italics to caption

prm1 - first actual data parameter, which has visible title in the infobox - "Parameter 1"

  • In the code: {{{prm1}}}
    • it's very simple and there is no function - if left empty, infobox will show "Parameter 1" title, but there will be nothing to show in another column

prm1 - second data parameter, with "Parameter 2" title

  • In the code:
    {{#if: {{{prm2|}}}|<tr> <td class="ibfobox-data-title">Parameter 2</td> <td class="ibfobox-data">{{{prm2}}}</td> </tr>}}
    • #if: again means it's optional, but if filled it will add a row with two columns

Styles

The table uses styles which determinate its look. Here we have:

  • style="", most notably in the header
  • and several classes
    • infobox for entire table - this wiki already has such class in Common.css page; most notably it puts the box into right side of the page and gives it background color and border
    • ibfobox-data-title - for column with data titles; will be a custom class in Template:Classic infobox/styles.css page - for educational purposes it will brighter than usual Wikipedia style
    • ibfobox-data - for second column, with data values; same as previous

Categories

With the aid of transclusion tags, infobox can place the page it's used on into a category (or several categories).

In case of this template, code:

{{#ifeq:{{NAMESPACE}}|Template|<!-- do nothing -->|[[Category:Some category]]}}

placed inside <includeonly> tag, will add the page into "Some category", unless the namespace of that page is "template" - hence "do nothing" commentary bit.

Usage

To use infobox on another page, this code must be used:

{{Classic infobox
|title =
|file = 
|caption = 
|prm1 = 
|prm2 = 
}}

Template:Classic infobox

Per break down above, the only obligatory parameter here {{{prm1}}}.

If everything is left empty, the output will be:

Code of filled up example:

{{Classic infobox
|title = This is the title
|file = De Alice's Abenteuer im Wunderland Carroll pic 15.jpg
|caption = How far into the template rabbit hole do you go?
|prm1 = Flowers
|prm2 = Mushrooms}}

Template:Classic infobox Gives: