Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Incubator escapee wiki:Template namespace
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Suggested practices == === Template names === {{shortcut|WP:TPN}} Template names should be made of one or more words, such as {{tlc|Train topics}}. The first character is not case-sensitive, so {{tlc|cleanup}} and {{tlc|Cleanup}} are the same template. All other characters are case sensitive, so {{tlc|cfd}} and {{tlc|cfD}} are not the same. Template names are easiest to remember if they follow standard English spelling, spacing, and capitalization (also see the [[Wikipedia:Naming conventions|naming conventions]] for articles). Avoid having templates whose names differ only in case, spacing, or punctuation. For templates with long names, [[Wikipedia:Redirect#Template_redirects|template redirects]] (often called shortcuts) can be created for ease of typing. For example, instead of typing {{tlc|Template link with subst}} the shortcut {{tlc|tls}} is available. === Sandbox for experiments === {{main|Wikipedia:Template sandbox and test cases}} If you wish to experiment with templates (and not have your experiments deleted before you are done with them), you may do so in the [[Template:Template sandbox|Template sandbox]]. You may also use the templates [[Template:X1|X1]], [[Template:X2|X2]], [[Template:X3|X3]], [[Template:X4|X4]], [[Template:X5|X5]], [[Template:X6|X6]], [[Template:X7|X7]], [[Template:X8|X8]], [[Template:X9|X9]], [[Template:X10|X10]], [[Template:X11|X11]], and [[Template:X12|X12]] for experimental purposes. To include a test template, use the form {{tlc|X1}} for template X1, {{tlc|X2}} for template X2, etc. Existing templates often each have their own [[Wikipedia:Template sandbox and test cases|sandbox and test case]] pages (especially those that use {{tl|Documentation}}). Changes should be thoroughly tested there before being applied to the main template, in order to prevent unintentional damage to many pages. === Readability of the code === For templates that have a large number of parameters, it can be helpful to place each parameter on a separate line and align the equals signs. This helps future editors to more easily read the wikicode. For example, if you wish to create a new [[Help:Infobox|infobox]] β which may contain dozens of parameters β your code might look like this: <pre>{{Infobox | header1 = Text of header1 | label2 = Text of label2 | data2 = Text of data2 | etc = etc }}</pre> Templates using many [[Help:Conditional expressions|conditional expressions]] often benefit from line spacing, such as the following code used in {{t|If either}} <syntaxhighlight lang=wikitext> {{#if:{{{1|}}} |{{{then|{{{3|}}}}}} |{{#if:{{{2|}}} |{{{then|{{{3|}}}}}} |{{{else|{{{4|}}}}}} }} }} </syntaxhighlight> While not necessary, the demonstrated linebreaks allow for easier parsing of which conditionals relate to which #if statement. === Line breaks === While line breaks in the body of a template code are useful for readability, line breaks at the beginning or end of template code could cause display issues on articles. Care should be taken when coding templates to ensure that there is no unnecessary whitespace. A single line break in an infobox may combine with a line break in an article to cause a paragraph break, or could cause an unwanted template in an inline template. As a general guideline, avoid two line breaks together in your template. These may "add up" with other line breaks in the article and be displayed as unwanted white space. For more information about line breaks as they affect wikitext, see [[Wikipedia:Line-break handling]]. To avoid unnecessary whitespace, ensure that any {{tag|noinclude|o}} tags are placed immediately after the template code. The following code is from {{t|questions}} and has good line break management. <syntaxhighlight lang=wikitext> {{notice|small=yes|If you want to ask a question, please see the [[Wikipedia:Questions]] page for guidance.}}<noinclude> [[Category:Wikipedia help templates]] </noinclude> </syntaxhighlight> === Substitution === {{main|Wikipedia:Substitution}} Invoking a template using the form : '''<code>{{<span style="color:red;">subst:</span>name of template ''(|parameters |...)''}}</code>''' (that is, inserting '''<code>subst:</code>''' immediately after the opening pair of curly brackets) will make a copy of the template text and place it on the page, where it will be viewable in the source. The template is no longer [[transclusion|transcluded]] and future changes to the template will not change the text. As a [[#Guideline|guideline]], this method should be used for any short, temporary messages which are removed quickly, such as on User_talk: pages. The standard new user {{tlx|Welcome}} message is a good example. Use subst: also if you need to edit the message after including it on the page. If you don't need to edit it, and would rather the message is automatically updated along with changes made to the template, don't use subst:. === Documentation === {{main|Wikipedia:Template documentation}} Because templates represent a step up in difficulty for the novice editor, documentation should be provided which describes its usage (optional parameters) and scope (where it should be used). There are two different ways to do this: One option is to use the {{t|documentation}} template to add a minor description directly onto the template page. As mentioned in {{slink||Line breaks}}, the first {{tag|noinclude|o}} tag should be placed on the same line as the last character of the actual template. For example: <syntaxhighlight lang=wikitext> '''This is a {{{1}}} article.'''<noinclude> {{documentation|content= Place this template on any article that requires description. It takes one parameter, an adjective used to describe the article. For example, {{article-describe|bad}} produces the text, '''This is a bad article.''' }} </noinclude> </syntaxhighlight> Another alternative is to create a formal [[Wikipedia:DOC|/doc subpage]] for the documentation (preferred for templates with multiple parameters, etc.). The {{t|documentation}} template is still called, but all of the displayed text will be transcluded from the template's /doc subpage. <syntaxhighlight lang=wikitext> '''This is a {{{1}}} article.'''<noinclude> {{documentation}} </noinclude> </syntaxhighlight> ===Modules=== {{main|Wikipedia:Lua}} Lua modules are sometimes used instead of templates to store reusable material. Reasons for this include usage of module-specific features such as [[loop (programming)|loops]] or stored values, and complex code is often easier to read and maintain in a module. If a module is easily implementable in a template it generally should be, since there are more users with experience editing templates. If a module is intended to be used in articles or talk pages, a template wrapper should generally be created to simplify usage without directly requiring the <code>#invoke</code> parser function. Documentation is then mostly located on the template's /doc page, with the module's documentation pointing to the template and/or explaining further technical details that are unnecessary at the primary template documentation. A template wrapper uses more of the [[WP:PEIS|post-expand include size limit]] than calling the module directly, therefore it may be necessary to avoid using one in articles that are near the limit.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)