T is a feature-packed example generator for brace-based wikitext. It allows users to link to and describe templates and module invocations using familiar syntax.
Installation[]
Usage[]
The basics[]
At its most basic, this template creates fancy links to other templates. For example, here's how you would link to Template:Sandbox:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox}}
|
|
(We'll be using Template:Sandbox throughout this tutorial, but any template will work—including T itself!)
Parameter descriptions[]
T wouldn't be very interesting if it was only able to generate links. Indeed, the template is more useful than that: it also accepts additional values after the name of the template, which are used to describe its parameters. Let's amend our previous example to include descriptions for {{{1}}} and {{{2}}}:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox|the first parameter|the second parameter}}
|
|
Note that, for technical reasons, parameter descriptions must occur sequentially. In other words, these will not work:
{{t|Sandbox|one=the first parameter|two=the second parameter}}
{{t|Sandbox|7=the seventh parameter|8=the eighth parameter}}
Parameter names[]
Despite the ominous warning above, there is a way to describe named parameters with T. Simply separate the name and description with the numeric character reference =, like so:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox|one=the first parameter|two=the second parameter}}
|
|
You can also do this with a magic word by adding equals with double brackets:
{{t|Sandbox|one{{=}}the first parameter|two{{=}}the second parameter}}
The latter form is preferable, since your editors are more likely to know what {{=}} does than =.
Blank descriptions[]
If you leave the value of a parameter description blank, it will default to .... For example:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox||param{{=}}}}
|
|
Literal parameter values[]
Sometimes when writing documentation, you'll want to talk about what happens when the user supplies a specific value to a parameter, rather than describing the parameter as a whole. You can do this in T by wrapping the value in single or double quotes, like so:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox|"my first literal"|name{{=}}'my second literal'}}
|
|
Empty values are also possible:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox|""|name{{=}}""}}
|
|
Note that the whole value needs to be in quotes, so this won't work:
{{t|Sandbox|this is "still" a parameter description}}
Escaping[]
T doesn't provide any means of escaping special characters like quotes. As with all other wikitext, you can use <nowiki> tags instead. For example:
| Wikitext input | Rendered output |
|---|---|
{{t|Sandbox|<nowiki>name{{=}}"value"</nowiki>}}
|
|
Flags[]
| Longhand | Shorthand |
|---|---|
invocation
|
i
|
multiline
|
m
|
subst
|
s
|
T allows you to modify how it behaves by enabling or disabling special flags. Each flag has both a longhand and a shorthand form, which are listed in the table to the right.
invocation (i)[]
Enabling the invocation flag switches T from transclusion mode, which describes a template, to invocation mode, which describes a module. These two modes are very similar, the only difference being that the latter requires the name of a function to call. For example, here's how you would link to Module:Sandbox:
| Wikitext input | Rendered output |
|---|---|
{{t|invocation=true|Sandbox|main}}
|
|
multiline (m)[]
Enabling the multiline flag forces T to put each parameter, as well as the opener and closer, on its own line. For example:
| Wikitext input | Rendered output |
|---|---|
{{t|multiline=true|Sandbox
|the first parameter
|two {{=}} the second parameter
}}
|
|
subst (s)[]
Enabling the subst flag causes T to prefix the name with subst::
| Wikitext input | Rendered output |
|---|---|
{{T|subst=true|Sandbox}}
|
|
{{t|invocation=true|subst=true|Sandbox|main}}
|
|
As a module[]
You can also use T from within another Lua module! They're largely similar, but there are a few differences to be aware of:
- There is a separate function for each mode, rather than defaulting to transclusion mode and using flags to switch to others.
- Arguments must be passed in the following order:
- Any required data, e.g. the template name in transclusion mode
- (Optional.) A sequential table with parameters
- (Optional.) A table with options, e.g. the
multilineflag
- Shorthand flag names are not available, in order to be more explicit.
- You can use a literal equals sign to separate parameter names from their descriptions (or values).
Here's are a few examples of the Lua syntax:
-- import the module
local t = require("Dev:T")
-- use `transclusion` for templates
local myFirstTemplateLink = t.transclusion("Sandbox")
-- parameters are the same as usual
local mySecondTemplateLink = t.transclusion("Sandbox", {
"a",
"b=c",
"'d'",
})
-- flags work, too
local myThirdTemplateLink = t.transclusion("Sandbox", {
"a",
"b=c",
"'d'",
}, {multiline = true})
-- use `invocation` for modules
local myFirstModuleLink = t.invocation("Sandbox", "main")
-- everything else is the same as `transclusion`
local mySecondModuleLink = t.invocation("Sandbox", "main", {
"a",
"b=c",
"'d'",
}, {multiline = true})
Documentation[]
Package items[]
T.transclusion(title, params, options)(function)- Generator for transclusion syntax, e. g.
{{foo}},{{:foo}}, or{{Template:Foo}}. - Parameters:
- Returns: A blob of wikitext describing a template. (string)
T.invocation(title, func, params, options)(function)- Generator for invocation syntax, e. g.
{{#invoke:foo|bar}}. - Parameters:
- Returns: A blob of wikitext describing a module. (string)
T.main(frame)(function)- Entry point from the wikitext side. Determines which generator to use based on the provided arguments.
- Parameter:
frameA frame object whose arguments will determine the correct generator to use. (table|Frame) - Returns: A blob of wikitext describing any brace-based syntax. (string)
TODO[]
- Extract CSS to stylesheet; transition from data-attributes to classes.
- Consider adding i18n for error messages, flags, &c.
- Consider adding generator(s?) for magic words and parser functions.
Changelog[]
- 0.1.0
- Initial revision. Ported Template:T to Lua in order to remove its 20-parameter limitation.
- 0.2.x
- Added named parameter syntax, e.g.
{{t|<template>|<name>{{=}}<description>}}. - 0.3.x
- Added the multiline flag, e.g.
{{t|multiline=true|<template>|<parameters>}}. - 0.4.x
- Added invocation mode, e.g.
{{t|invocation=true|<module>|<function>|<parameters>}}. - 0.5.x
- Completely rewrote the module to improve clarity and separation of concerns.
- Added
p.transclusionandp.invocationfor use in external Lua modules. - Minor improvements to parsing and the rendered output.
- 0.6.x
- Added literal parameter values, e.g.
{{t|<template>|"value"}}. - Added support for linking to templates that aren't in the
Template:namespace, e.g.{{t|User:Example/Template}} - Added the substitution flag, e.g.
{{t|subst=true|<template>|<parameters>}}. - Improved structure of rendered output with additional tags and metadata.