imported>RheingoldRiver Adding default set of pages |
the mass documenting |
||
| Line 1: | Line 1: | ||
{{ | '''Module:Template link renders a template's name as a clickable, brace-wrapped, formatted example — the engine behind {{tl|Tlg}} and the family of "template link" templates.''' | ||
__TOC__ | |||
== Overview == | |||
When documentation needs to show a template by name — like <code>{{tl|Navbox}}</code> displaying as a link reading <code>{{Navbox}}</code> — this module builds that text. It takes a template name plus optional sample parameters and produces a link to the template wrapped in literal <code>{{ }}</code> braces (using <code>nowiki</code> so they don't actually transclude). Many display options control bolding, italics, <code><code></code> styling, whether to show braces, and so on. | |||
This implements {{tl|Tlg}} ("template link general"); the many short aliases ({{tl|tl}}, {{tl|tlx}}, etc.) are thin wrappers around it. The wiki page for this module is just a redirect to Wikipedia's documentation for <code>Module:Template link general</code>, since this is essentially that well-known module. | |||
Editors use the template-link templates ({{tl|tl}}, {{tl|Tlg}}, …), not the module directly. | |||
== Functions / entry points == | |||
{| class="wikitable" | |||
! Function (#invoke) !! What it does !! Called by | |||
|- | |||
| <code>p.main</code> || Collects arguments (via {{ml|ArgsUtil}}'s <code>merge</code>) and hands them to <code>p._main</code>. The normal entry point. || {{tl|Tlg}} / {{tl|tl}} and related template-link templates | |||
|- | |||
| <code>p._main</code> || Does the actual work: builds the link to the named template, appends any sample parameters (separated by escaped pipes), and applies the requested formatting flags (bold, italic, code, braces, nowrap, etc.). Returns the finished wikitext. Can also show the expanded result or a link to Special:ExpandTemplates. || <code>p.main</code> (and Lua callers that already have an args table) | |||
|} | |||
== How it's used == | |||
Editors write one of the template-link templates, e.g.: | |||
<pre> | |||
{{tl|Navbox}} → {{Navbox}} | |||
{{tl|Sound|MyFile.ogg}} → {{Sound|MyFile.ogg}} | |||
</pre> | |||
Those templates are built on <code>{{#invoke:Template link|main|...}}</code>. The first positional argument is the template name; positional arguments 2+ are shown as sample parameters; named options control the look. | |||
Common options (all optional, presence-only flags unless noted): | |||
* <code>bold</code> / <code>italic</code> — bold the link / italicise the sample params. | |||
* <code>code</code> or <code>tt</code> — wrap in <code><code></code>; <code>plaincode</code> for borderless code; <code>kbd</code> for <code><kbd></code>. | |||
* <code>nolink</code> — show the name as plain text, not a link. | |||
* <code>brace</code> / <code>braceinside</code> — show extra literal braces. | |||
* <code>nowiki</code> — treat sample params as literal text. | |||
* <code>subst</code> — prefix the shown name with <code>subst:</code>. | |||
* <code>alttext</code> — override the displayed link text. | |||
* <code>nowrap</code> / <code>nowrapname</code> — prevent line wrapping. | |||
* <code>_show_result</code> — also expand the template and show its output after a "→". | |||
* <code>_expand</code> — append a link to Special:ExpandTemplates for the call. | |||
* <code>debug</code> — dump the parsed args. | |||
Ordinary editors should use {{tl|tl}} / {{tl|Tlg}} and the other wrappers; they rarely need raw <code>#invoke</code>. | |||
== Notes == | |||
* '''Namespace handling.''' A bare name is treated as a <code>Template:</code> page. A name containing a colon is checked against known namespaces: a real namespace prefix is kept as-is, otherwise it's still treated as a template title. A leading colon / other-namespace title is handled via <code>mw.title.new(name, 'Template')</code>. | |||
* '''Braces are literal.''' The surrounding <code>{{ }}</code> and the pipes between sample parameters are produced with <code>mw.text.nowiki</code> so the displayed example does not actually transclude or break the page. | |||
* '''Depends on {{ml|ArgsUtil}}''' for argument collection (<code>require('Module:ArgsUtil').merge</code>). | |||
* '''Origin.''' This is the Wikipedia "Template link general" module; the on-wiki doc is a {{tl|From Wikipedia}} redirect to that module's documentation, so the full option reference there applies. | |||
* '''Related:''' {{tl|Tlg}}, {{tl|tl}} and the other template-link wrappers, {{ml|ArgsUtil}}. | |||
Latest revision as of 11:55, 20 June 2026
Module:Template link renders a template's name as a clickable, brace-wrapped, formatted example — the engine behind {{Tlg}} and the family of "template link" templates.
Overview
When documentation needs to show a template by name — like displaying as a link reading {{Navbox}}
— this module builds that text. It takes a template name plus optional sample parameters and produces a link to the template wrapped in literal {{ }} braces (using nowiki so they don't actually transclude). Many display options control bolding, italics, styling, whether to show braces, and so on.
This implements {{Tlg}} ("template link general"); the many short aliases ({{tl}}, {{tlx}}, etc.) are thin wrappers around it. The wiki page for this module is just a redirect to Wikipedia's documentation for Module:Template link general, since this is essentially that well-known module.
Editors use the template-link templates ({{tl}}, {{Tlg}}, …), not the module directly.
Functions / entry points
Function (#invoke)
What it does
Called by
p.main
Collects arguments (via {{ArgsUtil}}m's merge) and hands them to p._main. The normal entry point.
{{Tlg}} / {{tl}} and related template-link templates
p._main
Does the actual work: builds the link to the named template, appends any sample parameters (separated by escaped pipes), and applies the requested formatting flags (bold, italic, code, braces, nowrap, etc.). Returns the finished wikitext. Can also show the expanded result or a link to Special:ExpandTemplates.
p.main (and Lua callers that already have an args table)
How it's used
Editors write one of the template-link templates, e.g.:
{{tl|Navbox}} → {{Navbox}}
{{tl|Sound|MyFile.ogg}} → {{Sound|MyFile.ogg}}
Those templates are built on {{...}}. The first positional argument is the template name; positional arguments 2+ are shown as sample parameters; named options control the look.
Common options (all optional, presence-only flags unless noted):
bold / italic — bold the link / italicise the sample params.
code or tt — wrap in ; plaincode for borderless code; kbd for .
nolink — show the name as plain text, not a link.
brace / braceinside — show extra literal braces.
nowiki — treat sample params as literal text.
subst — prefix the shown name with subst:.
alttext — override the displayed link text.
nowrap / nowrapname — prevent line wrapping.
_show_result — also expand the template and show its output after a "→".
_expand — append a link to Special:ExpandTemplates for the call.
debug — dump the parsed args.
Ordinary editors should use {{tl}} / {{Tlg}} and the other wrappers; they rarely need raw #invoke.
Notes
- Namespace handling. A bare name is treated as a
Template: page. A name containing a colon is checked against known namespaces: a real namespace prefix is kept as-is, otherwise it's still treated as a template title. A leading colon / other-namespace title is handled via mw.title.new(name, 'Template').
- Braces are literal. The surrounding
{{ }} and the pipes between sample parameters are produced with mw.text.nowiki so the displayed example does not actually transclude or break the page.
- Depends on
{{ArgsUtil}}m for argument collection (require('Module:ArgsUtil').merge).
- Origin. This is the Wikipedia "Template link general" module; the on-wiki doc is a
{{From Wikipedia}} redirect to that module's documentation, so the full option reference there applies.
- Related:
{{Tlg}}, {{tl}} and the other template-link wrappers, {{ArgsUtil}}m.