User:Jabberwock/templates

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search
This article is about making and editing templates. For using templates, see User:Jabberwock/codes#Templates.

So, why the f**k would you want to make a template? The existing ones are good enough. Maybe you want to win the Poo Lit Surprise though.

Basic techniques[edit | edit source]

A simple template is Template:Sample template 1. It looks like this: Template:Sample template 1 Its code:

{|align=center cellpadding=8 cellspacing=0 style="width:40em; background-color:#66ccff; border:solid 4px darkgrey;"
|[[File:Example.jpg|80px]]
|{{Q|This is a template with an example image.|Captain Obvious}}
|}

Note that it includes another template, namely Template:Q. This is allowed. To make new templates, you can copy the code and change the content and maybe the colors (#66ccff and darkgrey.) This is known an sporking.

Inputs[edit | edit source]

I created Template:Sample template 2 as an example that needs inputs. It's code:

{|align=center cellpadding=8 cellspacing=0 style="width:40em; background-color:#66ccff; border:solid 4px darkgrey;"
|[[File:Example.jpg|80px]]
|This template can take three inputs. The first input is {{{1}}}, the second is {{{2}}}, and the "fucking" input is {{{fucking}}}.
|}

Now I shall use {{Sample template 2|1234|5678|fucking = 999}}. It gives Template:Sample template 2 But what if there is no input? It becomes Template:Sample template 2

Solving the problem[edit | edit source]

We don't want ugly codes like {{{1}}} to show up in templates. So here is our new template, Template:Sample template 3.

{|align=center cellpadding=8 cellspacing=0 style="width:40em; background-color:#66ccff; border:solid 4px darkgrey;"
|[[File:Example.jpg|80px]]
|This template can take three inputs. The first input is {{{1|345}}}, the second is {{{2|678}}}, and the "fucking" input is {{{fucking|shit}}}.
|}

{{{1|345}}} means that if the input 1 doesn't exist, it says 345. {{{2|678}}} and {{{fucking|shit}}} work similarly. This time, if you don't input things, it says: Template:Sample template 3 If you only give the first input like {{Sample template 3|123}}, it gives Template:Sample template 3

Expr, if, and ifeq[edit | edit source]

For more information, see Help:Magic words and Help:Calculation.

Expr[edit | edit source]

The magical #expr can do complex multiplications and divisions in microseconds. Template:Sample template 4 uses it.

{|align=center cellpadding=8 cellspacing=0 style="width:40em; background-color:#66ccff; border:solid 4px darkgrey;"
|[[File:Example.jpg|80px]]
|This template multiplies the input by 17. <br/> The product is {{#expr:{{{1}}} * 17}}
|}

(In case you don't know, <br/> begins a new line.)

Let's input an arbitrary number. {{Sample template 4|372}} Template:Sample template 4 Note that you can also use #expr outside templates. For example, I can use {{#expr:135/(7+2)}} in this article. It gives 15.

If[edit | edit source]

The not-so-magical #if tells whether an input exists. For example, Template:Sample template 5's code is

{|align=center cellpadding=8 cellspacing=0 style="width:40em; background-color:#66ccff; border:solid 4px darkgrey;"
|[[File:Example.jpg|80px]]
|This template can take an input. <br/> {{#if:{{{1|}}}|The input is {{{1}}}.|Sadly, there is no input.}}
|}

In this template, #if tells whether {{{1|}}} exists. If there is a nonempty input, then it exists. But if there is none, then its value is an empty string. Let's see the effect of {{Sample template 5|123}}. Template:Sample template 5 And {{Sample template 5}} without an input. Template:Sample template 5

Ifeq[edit | edit source]

The #ifeq determines whether two things are equal. See Template:Sample template 6:

{|align=center cellpadding=8 cellspacing=0 style="width:40em; background-color:#66ccff; border:solid 4px darkgrey;"
|[[File:Example.jpg|80px]]
|This template can take an input. <br/> {{#ifeq:{{#expr:{{{1}}} mod 2}}|0|The input is even.|The input is odd.}}
|}

Now I'm testing the effect. {{Sample template 6|3}} gives: Template:Sample template 6 {{Sample template 6|4}} gives: Template:Sample template 6 It works.

Like #expr, you can use #if and #ifeq outside templates.