Template:Tlx/Documentation

Template page
Revision as of 00:19, 10 August 2016 by Thumper (talk | contribs) (→‎Examples: Fixed typo)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This template creates a linked, formatted example template call, to illustrate how a template is used. It is mainly intended to make writing template documentation easier. However, it can also be handy for creating sample template calls that people can easily copy and paste.

Usage

One argument is required, which is the name of the template.

{{tlx|clear}}

produces:

{{clear}}

which, as you can see, produces an example of how to call the clear template, along with a link to it.

If the template doesn't exist, this will produce a redlink. Watch out for capitalization. Normal wiki capitalization rules apply (the case of the first character doesn't matter, but every other character's case does - "foo" and "Foo" are the same, but "Foo" and "FOO" are not).

Parameters

To illustrate the use of parameters to a template, you simply add more parameters to the {{tlx}} call. For example:

{{tlx|clear|right}}

produces:

{{clear|right}}

You can add up to ten parameters this way. If you add more than that, the template will just replace the following parameters with "". (But see below for tricks to allow more parameters.)

Named parameters

If you want to demonstrate named parameters, you have to write the "=" using the {{=}} template:

{{tlx|main|Welcome to Solas Tempus DB|l1{{=}}The wiki's main page}}

produces:

{{main|Welcome to Solas Tempus DB|l1=The wiki's main page}}

You could also use "&#61;" or "<nowiki>=</nowiki>" to get the same effect. These all produce exactly the same output:

{{tlx|main|Welcome to Solas Tempus DB|l1{{=}}The wiki's main page}}
{{tlx|main|Welcome to Solas Tempus DB|l1&#61;The wiki's main page}}
{{tlx|main|Welcome to Solas Tempus DB|l1<nowiki>=</nowiki>The wiki's main page}}

Empty parameters

To illustrate an empty positional parameter, you can't simply leave a space.

{{tlx|tlx|1| |3}}

produces:

{{tlx|1|3}}

You have two options. You can manually force a space with an XML entity, like "&#32;" (which is a space):

{{tlx|tlx|1|&#32;|3}}

produces:

{{tlx|1| |3}}

Or you can use <nowiki> tags:

{{tlx|tlx|1|<nowiki />|3}}
{{tlx|tlx|1|<nowiki></nowiki>|3}}

both produce:

{{tlx|1||3}}

Special characters

There are four characters which have to be specially treated: "=", "|", "{", and "}". Also, spaces are ignored in some places, so if you want them, you have to manually add them.

Here are the ways you can handle each of the special characters:

"="
{{=}}
&#61;
<nowiki>=</nowiki>
"|"
{{!}} (caution: can fail in strange ways)
&#124;
<nowiki>|</nowiki>
"{"
&#123;
<nowiki>{</nowiki>
"}"
&#125;
<nowiki>}</nowiki>
Spaces
&#32;
<nowiki> </nowiki> (or as many spaces as you like)

Examples

Code Result Comments
{{tlx|clear}} {{clear}}
{{tlx|Clear}} {{Clear}} Honours capitalization. (Which means {{tlx|CLEAR}} would link to a different template.)
{{tlx|clear|both}} {{clear|both}}
{{tlx|tlx|1|2|3|4|5|6|7|8|9|10}} {{tlx|1|2|3|4|5|6|7|8|9|10}} Recognizes up to 10 parameters.
{{tlx|tlx|1|2|3|4|5|6|7|8|9|10|11|12|13}} {{tlx|1|2|3|4|5|6|7|8|9|10|}} Recognizes up to 10 parameters, but no more. (Although, see tricks.)
{{tlx|main|Thumper|l1=Super genius}} {{main|Thumper}} Can't just use "=".
{{tlx|main|Thumper|l1{{=}}Super genius}} {{main|Thumper|l1=Super genius}} {{=}} works.
{{tlx|tlx|a||b}} {{tlx|a|b}} You can't just skip parameters.
{{tlx|tlx|a|&#32;|b}} {{tlx|a| |b}} You can force a space using an XML escape.
{{tlx|tlx|a|<nowiki />|b}} {{tlx|a||b}} Or you can use <nowiki>.

Tricks

Beyond the parameter limit

The template only recognizes the first ten parameters, but you can "cheat" using either an XML escape, or "<nowiki>":

Code Result Comments
{{tlx|tlx|1|2|3|4|5|6|7|8|9|10}} {{tlx|1|2|3|4|5|6|7|8|9|10}} Recognizes up to 10 parameters.
{{tlx|tlx|1|2|3|4|5|6|7|8|9|10|11|12|13}} {{tlx|1|2|3|4|5|6|7|8|9|10|}} Recognizes up to 10 parameters, but no more.
{{tlx|tlx|1|2|3|4|5|6|7|8|9|10&#124;11&#124;12&#124;13}} {{tlx|1|2|3|4|5|6|7|8|9|10|11|12|13}} Extended with "&#124;".
{{tlx|tlx|1|2|3|4|5|6|7|8|9|<nowiki>10|11|12|13</nowiki>}} {{tlx|1|2|3|4|5|6|7|8|9|10|11|12|13}} Extended with "<nowiki>".

In fact, with "<nowiki>" you can extend the parameter list functionally infinitely, without having to worry about any special characters:

{{tlx|tlx|<nowiki>a=b|c=d|e={{f}}| spaces |... onward forever</nowiki>}}

produces:

{{tlx|a=b|c=d|e={{f}}| spaces |... onward forever}}

Name

What does "tlx" mean? It's short for "template link expanded".

The name comes from Wikipedia. I figured it was a good idea to replicate the name from there to here, for a couple reasons. First, because anyone who is going to use it is probably going to be somewhat familiar with wikicode... and it's more likely than not that they picked up that familiarity at Wikipedia. Second, because it makes it easier when people "borrow" handy templates from Wikipedia - they can just "borrow" the documentation as well, which often has lots of {{tlx}} templates in it.