Ta̱mpi̱let:Template link/doc
This is a documentation subpage for Ta̱mpi̱let:Template link. It contains usage information, categories and other content that is not part of the original ta̱mpi̱let page. |
--[[ -- This module produces a "redirect" hatnote. It looks like this: -- '"X" redirects here. For other uses, see Y.' -- It implements the Error: missing redirect parameter (help). template. --]]
local mHatnote = require('Module:Hatnote') local mHatList = require('Module:Hatnote list') local mArguments --lazily initialize local libraryUtil = require('libraryUtil') local checkType = libraryUtil.checkType local checkTypeMulti = libraryUtil.checkTypeMulti
local p = {}
-- Helper functions
local function getTitle(...) --Calls mw.title.new and returns either a title object, or nil on error local success, titleObj = pcall(mw.title.new, ...) return success and titleObj or nil end
-- Main functions
function p.redirect(frame) mArguments = require('Module:Arguments') local args = mArguments.getArgs(frame, {parentOnly=true}) --Get number of redirects local numRedirects = tonumber(frame.args[1]) or 1 -- Create the options table. local options = {} options.selfref = args.selfref return p._redirect(args, numRedirects, options) end
function p._redirect(args, numRedirects, options, currentTitle, redirectTitle, targetTitle) -- Validate the input. Don't bother checking currentTitle, redirectTitle or -- targetTitle, as they are only used in testing. checkType('_redirect', 1, args, 'table') checkType('_redirect', 2, numRedirects, 'number', true) numRedirects = numRedirects or 1 checkType('_redirect', 3, options, 'table', true) options = options or {} currentTitle = currentTitle or mw.title.getCurrentTitle() -- Get the table of redirects local redirect = {} for i = 1, numRedirects do -- Return an error if a redirect parameter is missing. if not args[i] then return mHatnote.makeWikitextError( 'missing redirect parameter', 'Template:Redirect#Errors', args.category ) end redirect[i] = args[i] end -- Generate the text. local formattedRedirect = {} for k,v in pairs(redirect) do formattedRedirect[k] = mHatnote.quote(v) end local text = { mHatList.andList(formattedRedirect) .. ' ' .. (#redirect == 1 and 'redirects' or 'redirect') .. ' here.', mHatList._forSee(args, #redirect + 1, {title = redirect[1], extratext = args.text}) } text = table.concat(text, ' ') -- Functionality for adding categories local categoryTable = {} local function addCategory(cat) if cat and cat ~= then -- Add by index to avoid duplicates categoryTable[string.format(, cat)] = true end end --Generate tracking categories local mhOptions = {} local redirTitle for k,v in pairs(redirect) do -- We don't need a tracking category if the template invocation has been -- copied directly from the docs, or if we aren't in main- or category-space. if not v:find('^REDIRECT%d*$') and v ~= 'TERM' -- and currentTitle.namespace == 0 or currentTitle.namespace == 14 then redirTitle = redirectTitle or getTitle(v) if not redirTitle or not redirTitle.exists then addCategory('Missing redirects') elseif not redirTitle.isRedirect then if string.find(redirTitle:getContent(), '#invoke:RfD') then addCategory('Articles with redirect hatnotes impacted by RfD') else addCategory('Articles with redirect hatnotes needing review') end else local target = targetTitle or redirTitle.redirectTarget if target and target ~= currentTitle then addCategory('Articles with redirect hatnotes needing review') end end end
-- Generate the options to pass to Module:Hatnote. if currentTitle.namespace == 0 and not mhOptions.selfref and redirTitle and redirTitle.namespace ~= 0 then -- We are on a mainspace page, and the hatnote starts with something -- like "Wikipedia:Foo redirects here", so automatically label it as -- a self-reference. mhOptions.selfref = true else mhOptions.selfref = options.selfref end end --concatenate all the categories local category = for k,v in pairs(categoryTable) do category = category .. k end
return mHatnote._hatnote(text, mhOptions) .. category end
return p
The template link template is a simple macro template used to display a template name as a link surrounded by braces, thus showing the template name as code rather than actually invoking it. Its primary use is in instruction and documentation where it is used to refer to a template by name without invoking it.
Note that this template may be used under the name "tee-el" (tl) as well as "tee-one" (t1)— both function the same way and produce the same results. This is not true for all such visually confusing templates containing a possible 1/l mix-up as they are not interchangeable.
{{Tla}} works exactly like {{tl}} with the addition of optionally displaying alternative label text (link label). {{tlg}} can include the use of parameters in the template (as {{{1}}}).
Examples
jhyukA short example of its use is:
Other longer examples:
Code | Result | Notes |
---|---|---|
{{tlScript error: No such module "params".}} | {{Void}} | Standard usage |
{{tlsScript error: No such module "params".}} | Ta̱mpi̱let:Tls | For templates that should be substituted |
{{tl2Script error: No such module "params".}} | {{X1}}
|
This formats the link to show how it would look in code (i.e., monospace font) |
{{tl2Script error: No such module "params".}} | {{3x}}
|
Same as above, for templates on another Wikimedia project (in this example, Meta, using m: ). See Interwiki codes.
|
{{tl2Script error: No such module "params".}} | {{WP}}
|
For templates on another language project |
{{tlScript error: No such module "params".}} | {{=)}} | Use the format {{tl|1=templatename}} if the template contains template coding characters such as {{=)}} or {{!}}
|
TemplateData
jhyukTemplateData for Template link
This template displays a template name as a link surrounded by braces, thus showing how the template name would be used in code. Its primary use is in instruction and documentation.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Template name | 1 | Positional parameter: the template name without the namespace prefix “Template:”, which is added automatically | Template | required |
See also
jhyuk- Ta̱mpi̱let:Tiw
- Ta̱mpi̱let:Tiw
- Ta̱mpi̱let:Tiw to produce a [t]emplate [l]ink with a single [p]arameter.
- Ta̱mpi̱let:Tiw to produce a [t]emplate [l]ink with an e[x]panded number of parameters.
- Ta̱mpi̱let:Tiw to produce a [t]emplate [l]ink that's [s]ubst:ituted, with a single [p]arameter.
- Ta̱mpi̱let:Tiw
- Ta̱mpi̱let:Tiw, tl or tlp in any namespace.
- Ta̱mpi̱let:Lcs
- Ta̱mpi̱let:Tiw to produce a [t]emplate [l]ink to a template [r]edirect.
General-purpose formatting
jhyukText style ↓ | {{tlg}} options[note 1]to achieve text style |
Link style | |||||
---|---|---|---|---|---|---|---|
Linked | Unlinked | Linked with subst | Unlinked with subst | Linked including braces | Linked with alternative text | ||
{{tlg}} options[note 1]to achieve link style |
— | DEFAULT | nolink=yes
|
subst=yes
|
nolink=yes
|
braceinside=yes
|
alttext=Foo 2=Foo
|
normal | DEFAULT | {{tlg}} {{tl}} Ta̱mpi̱let:Tlp |
{{tlf}} <template link> |
Ta̱mpi̱let:Tls Ta̱mpi̱let:Tlsu |
{{tlsf}} <template link> |
Ta̱mpi̱let:Tn | Ta̱mpi̱let:Tla |
code
|
code=yes
|
{{tl2}} {{tlx}} Ta̱mpi̱let:Tlxu |
{{tlc}} <template link> Ta̱mpi̱let:Tnull<template link> |
Ta̱mpi̱let:Tlxs | Ta̱mpi̱let:Tlsc <template link> |
— | |
monospace | plaincode=yes |
— | Ta̱mpi̱let:Tltss |
— | |||
kbd | kbd=yes | ||||||
bold | bold=yes
|
Ta̱mpi̱let:Tlb | — | ||||
bold+code
|
bold=yes
|
Ta̱mpi̱let:Tlxb | |||||
italic+code
|
italic=yes
|
Ta̱mpi̱let:Tlxi |
Other formatting templates
jhyukCode example | Effect | Notes |
---|---|---|
{{tl2|Hatnote|lang=fr}}
|
{{hatnote}} |
Supports linking to sister projects (e.g., fr:Hatnote) |
{{demo|<nowiki>{{Hatnote|lang=fr|Some text}}</nowiki>}}
|
{{hatnote|lang=fr|Some text}} |
Shows code and example |
{{tln|Hatnote}}
|
Ta̱mpi̱let:Tln | Produces a normal link to the template |
{{elc|Template:Hatnote}} {{elc|Template:Hatnote|Hatnote}}
|
Ta̱mpi̱let:Elc Ta̱mpi̱let:Elc |
Formats wikilink, with optional piped link text and blended suffix |
{{ml|Example|hello}}
|
{{#invoke:Example|hello}} | Counterpart to {{tl}} for linking to Lua modules |
{{mlx|Example|hello}}
|
{{#invoke:Example|hello}} |
Counterpart to {{tlx}} for linking to Lua modules |
{{para|title|<var>book title</var>}}
|
|title=book title |
Formats template parameters for display, with or without values |
{{sclx|LASTING}}
|
Ta̱mpi̱let:Sclx | Takes a shortcut suffix in project namespace and displays it with brackets and the WP: alias in a <code>...</code> tag.
|
{{tag|ref}} {{xtag|templatedata}}
|
<ref>...</ref> <templatedata> |
Formats [X]HTML tags; can add content, choose opening, closing, or self-closing |
{{dtl|Ping project}}
|
Ta̱mpi̱let:Dtl | Wikidata counterpart to {{tl}} |
{{pf|if}} {{pf|if|{{{1}}}|true|false}}
|
{{#if}} {{#ifTa̱mpi̱let:Colon{{{1}}}|true|false}} |
Parser function equivalent to {{tl}} |
{{magic word|uc:}}
|
Ta̱mpi̱let:Magic word | Magic word links |
With utility links
jhyukCode example | Effect |
---|---|
{{lt|Hatnote}}
|
Ta̱mpi̱let:Lt |
{{lts|Hatnote}}
|
Ta̱mpi̱let:Lts |
{{t links|Hatnote}}
|
Ta̱mpi̱let:T links |
{{tfd links|Hatnote}}
|
Ta̱mpi̱let:Tfd links |
{{tetl|Hatnote}}
|
Ta̱mpi̱let:Tetl |
{{tsetl|Hatnote}}
|
Ta̱mpi̱let:Tsetl |
{{ti|Hatnote}}
|
Template:Hatnote (talk⧼dot-separator⧽links⧼dot-separator⧽edit) |
{{tic|Hatnote}}
|
Ta̱mpi̱let:Tic |
{{tim|Hatnote}}
|
Ta̱mpi̱let:Tim |
{{tiw|Hatnote}}
|
Ta̱mpi̱let:Tiw |
{{tlt|Hatnote}}
|
Ta̱mpi̱let:Tlt |
{{ttl|Hatnote}}
|
Ta̱mpi̱let:Ttl |
{{twlh|Hatnote}}
|
Ta̱mpi̱let:Twlh |
Ghyuap di̱n tyan: <ref>
tags exist for a group named "note", but no corresponding <references group="note"/>
tag was found