Jump to content

Ta‌̱mpi‌̱let:Template link/doc

Neet di̱ Wikipedia

--[[ -- 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}}}).

A short example of its use is:

{{tlScript error: No such module "params".}}
which generates
{{Example}}

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

[jhyuk a̱tyin ka]
This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. Click here to see a monthly parameter usage report for this template based on this TemplateData.

TemplateData 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.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Template name1

Positional parameter: the template name without the namespace prefix “Template:”, which is added automatically

Templaterequired

General-purpose formatting

[jhyuk a̱tyin ka]
Comparison of template-linking templates according to the styles of generated text and link produced
Text 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|subst=yes braceinside=yes alttext=Foo
2=Foo
normal DEFAULT {{tlg}}[note 1]
{{tl}}
Ta‌̱mpi‌̱let:Tlp[note 2]
Ta‌̱mpi‌̱let:Tlu[note 3]
{{tlf}}[note 2]
<template link>
Ta‌̱mpi‌̱let:Tls
Ta‌̱mpi‌̱let:Tlsu[note 3]
{{tlsf}}[note 2]
<template link>
Ta‌̱mpi‌̱let:Tn Ta‌̱mpi‌̱let:Tla
code code=yes {{tl2}}
{{tlx}}
Ta‌̱mpi‌̱let:Tlxu[note 3]
{{tlc}}[note 2]
<template link>
Ta‌̱mpi‌̱let:Tnull<template link>
Ta‌̱mpi‌̱let:Tlxs Ta‌̱mpi‌̱let:Tlsc[note 2]
<template link>
monospace plaincode=yes[note 4] Ta‌̱mpi‌̱let:Tltss[note 5]
kbd kbd=yes[note 5]
bold bold=yes Ta‌̱mpi‌̱let:Tlb
bold+code bold=yes|code=yes Ta‌̱mpi‌̱let:Tlxb
italic+code italic=yes|code=yes Ta‌̱mpi‌̱let:Tlxi

Ta‌̱mpi‌̱let:NoteFoot

Other formatting templates

[jhyuk a̱tyin ka]
Templates producing specialised formatting effects for given templates, modules or parameters
Code 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
[jhyuk a̱tyin ka]
Templates producing utility links for a given template (Hatnote used here as example)
Code 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