Template:Template link code/doc: Difference between revisions

From Space Station 14 Wiki
Template:Template link code/doc
m (1 revision imported)
(Replaced content with "#REDIRECT [[Wikipedia:{{subst:FULLPAGENAME}}]]")
Tag: Replaced
 
Line 1: Line 1:
{{Documentation subpage}}
#REDIRECT [[Wikipedia:Template:Template link code/doc]]
{{high risk}}
 
== Purpose and naming ==
When a template name with [[brace]]s <nowiki>{{ }}</nowiki> is to be shown in documentation, the braces have to be escaped in some way so it doesn't become an actual call to the template. Instead of using <code>&lt;nowiki&gt;&lt;/nowiki&gt;</code> tags you can write it more simply and concisely by using the {{tlc|tlc}} template.
 
This template works similarly to {{tl|tl}} and {{tl|tlx}}, but doesn't make the template name into a link (template link cleared). When writing documentation you might want to avoid a lot of unnecessary links, since they can decrease readability. So on the first occurrence of a template name use {{tlx|tl}} or {{tlx|tlx}}, and then use {{tlc|tlc}} thereafter.
The name was based on {{tlx|tl}} '''t'''emplate '''l'''ink, despite the fact that, unlike the actual {{tlc|tl}} template, these templates don't include an actual link.
 
===Basic operation===
The template looks like this (code is to the left; actual rendering to the right): {{tlc|tlc|name|parameters}} → {{tlc|name|parameters}}
 
==Documentation==
 
===Functional details===
* This template takes another ''template-name'' and some associated [[Help:Pipe trick|pipe-tricked]] [[m:Parameter#Parameters|(numbered) parameters]] (or 'pass parameters'), and displays them as an 'example demonstration' of how the ''template-name'' template could be coded, literally. Its primary use is in instruction and documentation.
* It shows a template name and up to eight parameters, including empty parameters.
* It prevents [[line wrap]]s in its output.
 
===Usage===
{{tlc|Tlc|Template|first_parameter|second|third|...|eighth}} → {{Tlc|Template|first_parameter|second|third|fourth|fifth|sixth|seventh|eighth}}
=== Examples ===
{| class="wikitable" style="background-color: #FFEFD5" <!-- This background color helps keep code spans visible. -->
! Code !! Result !! Comment
|-
| {{tlc|tlc}} || {{tlc}} || Shows its own syntax.
|-
| {{tlc|tlc|name}} || {{tlc|name}} ||
|-
| {{tlc|tlc|name|one}} || {{tlc|name|one}} ||
|- style="background-color: #FFEBCD;"
| {{tlc|tlc|name|one|two}} || {{tlc|name|one|two}} ||
|- style="background-color: #FFEBCD;"
| <code><nowiki>{{tlc|name|a|b|c|d|e|f|g|h|i|j}}</nowiki></code> || {{tlc|name|a|b|c|d|e|f|g|h|i|j}} || Shows up to eight parameters. The rest are dropped.
|- style="background-color: #FFEBCD;"
| {{tlc|tlc|name|||three|four}} || {{tlc|name|||three|four}} || Also shows empty parameters.
|- style="background-color: #FFEBCD;"
| {{tlc|tlc|name|||three||}} || {{tlc|name|||three||}} || Even shows empty parameters that come in the end.
|- style="background-color: #FFEBCD;"
| {{tlc|tlc|name|one{{=}}a|two{{=}}b}} || {{tlc|name|one=a|two=b}} || The use of equal signs is a problem, but there is a fix; see next row.
|- style="background-color: #FFEBCD;"
| {{tlc|tlc|name|one{{((}}{{=}}{{))}}a|two{{((}}{{=}}{{))}}b}} || {{tlc|name|one{{=}}a|two{{=}}b}} || Use <code><nowiki>{{=}}</nowiki></code> in place of an equal sign, so that it gets rendered properly.
|- style="background-color:#FFEBCD"
| {{tlc|tlc|name|{{tlf|IPA|/tʃ/}}|two}} || {{tlc|tlc|name|{{IPA|/tʃ/}}|two}} || Nested template calls also cause problems ...
|-
| <code><nowiki>{{tlc|name|{{tlf|IPA|/tʃ/}}|two}}</nowiki></code> || {{tlc|tlc|name|{{tlf|IPA|/tʃ/}}|two}} || ... but there are ways to get around this issue, also.
|-
| <code><nowiki>{{tlc|name|{{((}}IPA{{!}}/tʃ/{{))}}|two}}</nowiki></code> || {{tlc|tlc|name|{{tlf|IPA|/tʃ/}}|two}} || ... another way to do the same thing, using <code><nowiki>{{((}}</nowiki></code>, <code><nowiki>{{!}}</nowiki></code> and <code><nowiki>{{))}}</nowiki></code> to insert literal <code><nowiki>{{</nowiki></code>, <code><nowiki>|</nowiki></code> and <code><nowiki>}}</nowiki></code>, respectively.
|}
 
An alternative to using constructs such as <code><nowiki>{{=}}</nowiki></code> and <code><nowiki>{{tlf|...}}</nowiki></code> to prevent characters from getting interpreted syntactically is to use <code><nowiki><code>&lt;nowiki>...&lt;/nowiki></code></nowiki></code>, which will prevent <em>all</em> characters from being interpreted.  For example, in place of
<code><nowiki>{{tlc|name|one{{=}}{{tlf|IPA|/tʃ/}}|two}}</nowiki></code>
you can use
<code><nowiki><code>&lt;nowiki>{{name|one={{IPA|/tʃ/}}|two}}&lt;/nowiki></code></nowiki></code>
Both render as
<code><nowiki>{{name|one={{IPA|/tʃ/}}|two}}</nowiki></code>
 
If a vertical display with parameters on their own lines is desired, this can also be laid out manually in this manner, or more rapidly done with <code><nowiki><pre>...</pre></nowiki></code>.
 
Here is the code to emulate {{tlc|tlc}} using <code>&lt;nowiki&gt;</code>:
 
{|
! Using templates: !! Using <code>&lt;nowiki&gt;</code>: !! Rendered result:
|-
|style="padding-right: 50px;"| <code><nowiki>{{tlc|name|one{{=}}a|two{{=}}b}}</nowiki></code>
|style="padding-right: 50px;"| <code><nowiki>&lt;code&gt;&lt;nowiki&gt;{{name|one=a|two=b}}&lt;/nowiki&gt;&lt;/code&gt;</nowiki></code>
|<code><nowiki>{{name|one=a|two=b}}</nowiki></code>
|}
 
===Limitations===
As documented at [[Help:Template#Problems and workarounds]], template arguments starting with one of the four MediaWiki magic characters <code>:</code> <code>;</code> <code>*</code> or <code>#</code> are interpreted ''as if'' they were at the beginning of a line, and are formatted as HTML lists.  To avoid this, references to {{tlc|<nowiki/>*}} or {{tlc|&#35;expr}} must have the first character escaped.  You can either use {{tag|nowiki|s}} or an escape like <code>&amp;#35;</code>.
 
==See also==
{{Template-linking templates}}
 
<includeonly>{{Sandbox other|
| <!-- ADD CATEGORIES BELOW THIS LINE, PLEASE: -->
[[Category:Template namespace templates]] <!--but not e.g. Category:Internal template-link templates, as these templates do not include links to templates. -->
[[Category:Wikitext typing-aid templates]]
}}</includeonly>

Latest revision as of 22:48, 20 February 2022