Chapter 2: Making your first template

From MicroWiki Guides
Jump to navigation Jump to search
Cupertinoguides.png

This page is apart of the Cupertino Guides project, a project by the Cupertino Alliance.

Previous: Templates

As we alluded to in the last lesson, templates are just containers of information that can be shared between various wiki pages. This means that you can basically put anything in Templates, so let's go over what templates should optimally be used for, as well as how to make one.

Should I make this a template?

Templates should really be made for at least one of these purposes:

  • If it contains lots of complicated markup;
  • For formatting purposes (like on the MicroWiki front page);
  • If it is meant to be used on other pages.

If it doesn't fulfill those criteria, it is recommended to incorporate the template on your page. This is because templates can be less convenient to edit as you have to find the template page to edit it, and you won't be able to preview the whole page when you edit your template.

Creating your template page

On CupertinoGuide/What is MicroWiki, we told you that template pages start with Template:. Knowing this, go create your page, and start your page title with Template:. After the colon, name your template (you can use spaces and symbols).

For the example above, the template's name would be Cupertino Alliance. To use the template, do {{Cupertino Alliance}}.

Naming for infobox templates

It is usual for infobox templates to usually be named as Template:Infobox <thing>. If you plan to make an infobox template, ensure that you name it this way.

Template special characters

There are two important special characters that are used in templates.

Three curly parentheses with a vertical line

The three curly parentheses with a vertical line indicate a parameter you can fill in. These would usually look like:

{{{Cupertino Alliance Factbook|}}}

which will allow you to fill in a value for the parameter "Cupertino Alliance Factbook"

|Cupertino Alliance Factbook = <value>

If statement

An if statement means that something needs to be fulfilled in order for an action to be done. This looks like:

{{#if:{{{parameter1|}}}|{{{parameter2|}}}}}

This translates to:

If {{{parameter1|}}} has a value, then {{{parameter2|}}} will appear.

Also take the example from last lesson, where |head of state = wasn't appearing because |hos_name ='s value was missing. Template:Infobox nation

{{Infobox nation
|name = Obamaland
|head of state = President}}

The above example failed to appear, telling us that the label or data parameters may have an "if" template.

...this can mean that you will have to fulfill both of those parameters in order for a label to appear. Take the below example.

|label19 = {{#if:{{{head of state|}}}|<small> - {{{head of state|}}}</small>}}
|data19 = {{#if:{{{hos_name|}}}|<small>{{{hos_name|}}}</small>}}

{{#if:{{{head of state|}}}|<small> - {{{head of state|}}} tells us that we need to fulfill |head of state = in order for |hos_name = to appear. Template:Infobox nation

{{Infobox nation
|name = Obamaland
|head of state = President
|hos_name = Obama}}

Creating text templates

To create pages with just text and photos (i.e. no infoboxes), simply write like you are writing a wiki page. Once you are done, save it and use it.

Creating text templates with a parameter

To create one with text you can enter, consider the example below:

Pencils are better than pens because {{{reason|}}}

This allows us to type in a reason into the |reason = parameter. Naming our template Template:CupertinoGuidePencil, the final product can look like:

Pencils are better than pens because you can erase them.
{{CupertinoGuidePencil
|reason = you can erase them.}}

We can also add boldness, italics, hyperlinks, and more like this:

I really like [[w:{{{Youtuber|}}}|{{{Youtuber|}}}]] who lives in the '''State of {{{State|}}}''' and makes videos like ''{{{Video|}}}''!

The formatting may look strange when you preview it, but continue. Naming our template Template:CupertinoGuideNorthCarolina, the final product can look like:

I really like MrBeast who lives in the State of North Carolina and makes videos like "Selling homes for $1"!
{{CupertinoGuideNorthCarolina
|Youtuber = MrBeast
|State = North Carolina
|Video = "Selling homes for $1"}}

Of course, if you plan to make templates for main space pages, make sure they use encyclopedia-appropriate language.

Creating text templates with an if statement

To create one with an if statement, consider the following example below:

The State of [[Vishwamitra]] is a micronation. {{#if:{{{location|}}}|It is located in [[w:India|India]]}}.

Naming our template Template:CupertinoGuideVishwamitra, it would look like:

The State of Vishwamitra is a micronation. .
{{CupertinoGuideVishwamitra}}

If we add something to |location = however, it would look like:

The State of Vishwamitra is a micronation. It is located in India.
{{CupertinoGuideVishwamitra 
|location = yes}}

Notice how the value in |location = (in this case, "yes") does not appear. The if statement works however since a value is added- it doesn't care what is in the value however. If we want the text in the value to appear, consider this:

The Kingdom of [[Atiera]] is a member of the Cupertino Alliance. {{#if:{{{dateofadmission|}}}|It was admitted on {{{dateofadmission|}}}.}}

Naming our template Template:CupertinoGuideAtiera, it would look like:

The Kingdom of Atiera is a member of the Cupertino Alliance.
{{Template:CupertinoGuideAtiera}}

If we added the date of admission for Atiera in |dateofadmission = however, it would look like:

The Kingdom of Atiera is a member of the Cupertino Alliance. It was admitted on 7 July 2020.
{{Template:CupertinoGuideAtiera
|dateofadmission = 7 July 2020}}

Notice how "7 July 2020" appears in the bottom example, but we didn't add "7 July 2020" in our original template text. This is because we used {{{dateofadmission|}}} on both sides of the if statement, as opposed to our first example where {{{location|}}} appeared only on the left.

Creating infobox templates

Infobox templates use Template:Infobox. Start your template page with

{{Infobox

The template uses |data = and |label =. Each data and label corrisponds to a number, for example:

|data2 = will connect to |label2 =

Note that you do not have to have every data parameter connected up, but each label needs to be connected to a data parameter. For example:

|data1 = works by itself.
|label2 = will not work without |data2 =

Singular data sections are usually used for titles or sections.

Let's start with a title. Type in |data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}. This will allow |data1 = to hide if the user chooses not to have a title. Our text should look like:

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}

Let's add an area to add a photo:

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}
|data2 = {{{photo|}}}

...a couple labels and data parameters:

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}
|data2 = {{{photo|}}}
|label3 = Established
|data3 = {{{established|}}}
|label4 = Currency unit
|data4 = {{{currency|}}}

Let's create a new section. We can do that with a singular data parameter.

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}
|data2 = {{{photo|}}}
|label3 = Established
|data3 = {{{established|}}}
|label4 = Currency unit
|data4 = {{{currency|}}}
|data5 = Currency information

For the inflation rate, let's use the currency name. For that, use {{{currency|}}}.

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}
|data2 = {{{photo|}}}
|label3 = Established
|data3 = {{{established|}}}
|label4 = Currency unit
|data4 = {{{currency|}}}
|data5 = Currency information
|label6 = {{{currency|}}} inflation rate
|data6 = {{{inflation|}}}
|label7 = Issuer
|data7 = {{{bank|}}}

Let's end our template with }} and it should look like:

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}
|data2 = {{{photo|}}}
|label3 = Established
|data3 = {{{established|}}}
|label4 = Currency unit
|data4 = {{{currency|}}}
|data5 = Currency information
|label6 = {{{currency|}}} inflation rate
|data6 = {{{inflation|}}}
|label7 = Issuer
|data7 = {{{bank|}}} }}

Script error: No such module "Infobox".Template:Template other Let's name our template Template:CupertinoGuideCurrency. If we use our template now, it looks good- however if I don't have anything listed for {{{inflation|}}} or {{{bank|}}}, "Currency information" still appears!

{{CupertinoGuideCurrency
|name = Weg Gogo
|photo = [[File:Gogo2.jpeg|150px]]
|currency = Gogo
}}

To fix this, let's add an if template to |data5 =

{{Infobox
|data1 = {{#if:{{{name|}}}|<big>''' {{{name|}}} '''</big>}}
|data2 = {{{photo|}}}
|label3 = Established
|data3 = {{{established|}}}
|label4 = Currency unit
|data4 = {{{currency|}}}
|data5 =  {{#if:{{{inflation|}}}{{{bank|}}}|Currency information}}
|label6 = {{{currency|}}} inflation rate
|data6 = {{{inflation|}}}
|label7 = Issuer
|data7 = {{{bank|}}} }}

This if statement is a bit different. If either {{{inflation|}}} and / or {{{bank|}}} has a value, then "currency information" appears. Save and name it Template:CupertinoGuideCurrency two Script error: No such module "Infobox".Template:Template other

{{CupertinoGuideCurrency two
|name = Weg Gogo
|photo = [[File:Gogo2.jpeg|150px]]
|currency = Gogo
}}

Here is the template with everything on it: Script error: No such module "Infobox".Template:Template other

{{CupertinoGuideCurrency two
|name = Weg Gogo
|photo = [[File:Gogo2.jpeg|150px]]
|established = 2020
|currency = Gogo
|inflation = 4.2%
|bank = Bank of Wegmat
}}

Feel free to add more or fewer sections, data, or labels to fit your needs. And that is your first infobox template!