Help:Templates: Difference between revisions

From The Reed and Rite
mNo edit summary
mNo edit summary
Line 200: Line 200:
: {{for|cosmere|oodles of information|this page about the cosmere}}
: {{for|cosmere|oodles of information|this page about the cosmere}}


== Editing Templates ==
Creating and editing templates is an advanced topic. This section will cover the basics of doing so. Feel free to make use of the {{t|test}} template to experiment with edits to existing templates or creating new ones.
=== Includeonly and Noinclude ===
;<code><nowiki><includeonly></nowiki></code> Tag
: Everything you want the template to do when used on other pages should be sandwiched between <code><nowiki><includeonly></nowiki></code> and <code><nowiki></includeonly></nowiki></code> tags.
;<code><nowiki><noinclude></nowiki></code> Tag
: The template's documentation, and anything else you want to show up on the template page itself, must be sandwiched between <code><nowiki><noinclude></nowiki></code> and <code><nowiki></noinclude></nowiki></code> tags.
=== Parameters ===
;Named Parameters
: ''Named'' parameters are referred to by their name in triple braces. For example, the named parameter "books"  in the {{t|character}} template is referred to as <code>{{{books}}}</code>.
;Unnamed Parameters
: ''Unnamed'' parameters are referred to by the order they are entered. For example, the first unnamed parameter that is entered in the {{t|book ref}} template is referred to as <code>{{{1}}}</code>, while the second is referred to as <code>{{{2}}}</code>.
;Defaults
: Provide a default value for parameters by including a vertical bar (<code>|</code>) followed by the default value. To use a null default value, enter nothing after the vertical bar. For example, if you want the first unnamed parameter to have a default value of "Sanderson", use <code><nowiki>{{{1|Sanderson}}}</nowiki></code>.
=== Parser Functions ===
There are a number of functions that can be used to generate different results based on the input provided. For an extensive list, see [https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions MediaWiki's Parser Functions] page. Here are some of the basics:
;Uppercasing Text
: This function converts a string of text to all uppercase.
: ''Use:'' <code><nowiki>{{uc: TEXT}}</nowiki></code>, where <code>TEXT</code> is the text to be converted.
: ''Example:'' <code><nowiki>{{uc: heLLo}}</nowiki></code> produces <code>HELLO</code>.
;Lowercasing Text
: This function converts a string of text to all lowercase.
: ''Use:'' <code><nowiki>{{lc: TEXT}}</nowiki></code>, where <code>TEXT</code> is the text to be converted.
: ''Example:'' <code><nowiki>{{lc: heLLo}}</nowiki></code> produces <code>hello</code>.
;String Compare
: This function compares two strings of text and provides one of two results.
: ''Use:'' <code><nowiki>{{#ifeq: A|B|Result1|Result2}}</nowiki></code>, where <code>A</code> and <code>B</code> are the strings of text. If <code>A=B</code> then <code>Result1</code> is returned; otherwise, <code>Result2</code> is returned.
: ''Example:'' <code><nowiki>{{#ifeq: dog|dog|same|different}}</nowiki></code> produces <code>same</code> and <code><nowiki>{{#ifeq: dog|cat|same|different}}</nowiki></code> produces <code>different</code>.
;If-Then
: This function checks if a parameter exists and provides one of two results.
: ''Use:'' <code><nowiki>{{#if: A|Result1|Result2}}</nowiki></code>, where <code>A</code> is some parameter. If <code>A</code> exists (i.e. it isn't null) then <code>Result1</code> is returned; otherwise, <code>Result2</code> is returned.
: ''Example:'' If a second unnamed parameter is provided, <code><nowiki>{{#if: {{{2|}}}|hello|goodbye}}</nowiki></code> produces <code>hello</code>. If not, it produces <code>goodbye</code>.
;Case-Switch
: This function performs a series of string compares until a "true" result is found.
: ''Use:'' <code><nowiki>{{#switch: X|A=Result1|B=Result2|C=Result3|etc.|Default}}</nowiki></code>, where <code>X</code> is compared to <code>A</code>, <code>B</code>, and so on. The first match provides the corresponding result. A final, default result may be provided in case no match is found.
: ''Example:'' <code><nowiki>{{#switch: cat|dog=bark|cat=meow|growl}}</nowiki></code> produces <code>meow</code> and <code><nowiki>{{#switch: bear|dog=bark|cat=meow|growl}}</nowiki></code> produces <code>growl</code>.
=== System Variables ===
There are a few system variables which provide different values as needed. These are given in all caps between double curly braces. For an extensive list, see [https://www.mediawiki.org/wiki/Help:Magic_words MediaWiki's Magic Words] page. The two most common are:
;Pagename
: <code><nowiki>{{PAGENAME}}</nowiki></code> provides the name of the page/article. If used in this page it would yield <code>Templates</code>.
;Namespace
: <code><nowiki>{{NAMESPACE}}</nowiki></code> provides the name of the page's namespace. If used in this page it would yield <code>Help</code>.
=== Comments ===
Comments inside of <code><nowiki><includeonly></nowiki></code> tags can be provided between <code><nowiki><!--</nowiki></code> and <code><nowiki>--></nowiki></code>.
Note: You might see a lot of these in existing templates, at the beginning and end of each line. White space can do strange things in templates, and so it is best to eliminate unnecessary white space by putting it inside of comments. One notable exception is inside tables, between the <code>|-</code> and the first cell <code>|</code>, which means the infobox {{t|row/kv}} (et al) can be nicely spaced without consequence.





Revision as of 23:39, 24 March 2025

Table of Contents
Contents | Introduction | Guidelines | Markup | References | Images | Categories | Templates | What's Next?

Introduction

Templates are standard wiki pages whose content is designed to be transcluded (embedded) inside other pages. They enable a user to simplify complex and repetitive processes. You embed this content into other pages through the use of a coded tag. In this article we'll go over the basics of using templates, some useful templates that are already available, and an introduction to creating your own templates. For a more in depth guide on templates, check out Mediawiki's Help article.

Basics of Templates

Templates are easy to recognize as they are enclosed by double curly braces. ({{ and }}) To use one you must first indicate the name of the template you want to use, and then define various parameters. All of the elements between the double curly braces are separated by vertical bars. (|) The number and type of parameters will vary depending on the template.

Some templates will be written in a single line of text, but some may span multiple lines. The more complex it is, the more likely it is to span multiple lines—this is to help with clarity in usage. For example:

A Single Line Template A Multi-Line Template
{{template name|parameter1|parameter2|parameter3}}
{{template name
|parameter1
|parameter2
|parameter3
}}

Parameters

Parameters come in two varieties: Named and Unnamed (also sometime called "Anonymous"). Templates will use one or the other, or even sometimes both. You can see the exact parameters a template uses by checking out its template page.

Named Parameters
Named parameters can be recognized by their use of an equals sign (=), which is required with a named parameter. The equals sign is followed by your input. For example:
{{template name|parameter1=INPUT}}
In this example parameter1= is a named parameter because of its use of an equals sign. INPUT would be replaced by your input.
Unnamed Parameters
Unnamed parameters should be completely replaced by your input. For example:
{{template name|INPUT}}
In this example INPUT is an unnamed parameter, and would be replaced by your input. Note that no other text is required beyond your input.

Parameter Examples

Let's take a look at some templates in action.

Example: Named Parameters
This example demonstrates a {{Character}} template, which uses named parameters.
Note that the name of the template comes first. ({{character), followed by the named parameters.
You Type You Get
{{character
|name=Beth Brower
|image=Beth Brower-2.jpg
|caption=Our Undaunted Author
|profession=Author, Owner of Cat
|titles=''The Right Honorable Beth''
}}
Beth Brower
Our Undaunted Author
Our Undaunted Author
Our Undaunted Author
ProfessionAuthor, Owner of Cat
TitlesThe Right Honorable Beth


Example: Unnamed Parameters
This example demonstrates a {{Quote}} template, which uses unnamed parameters.
You Type You Get
{{quote|My existence of the last three years has been nothing but incident.|Emma M. Lion}}
“

My existence of the last three years has been nothing but incident. ”

—Emma M. Lion


Example: Mix of Parameters
This example demonstrates an {{Image}} template, which uses a mix of named and unnamed parameters.
You Type You Get
{{image|Pen.png|A pen nib silhouette.|artist=Declan Lion|side=left|width=200px}}
A pen nib silhouette.

Types of Templates

Next we'll go over the most common templates you will encounter:

Information Boxes

Most commonly known as Infoboxes, these templates add a table of information to the top right of articles pages. (These are present on most articles on Wikipedia.) They contain basic information pertaining to the subject of the article. There are infoboxes for each of the main content categories (e.g., {{book}}, {{character}}, {{location}}), but there are a few other more specialized ones.

Navigation Boxes

Called navboxes for short, these templates create the tables at the bottom of pages that link to other important articles that are related to the same book or series. Most series or standalone books have a navbox that refers to important characters, places, etc. Navboxes are placed at the end of the article, directly after the <references /> tag.

For a full list of navigation templates, see Category:Navigation.

Notices

Notice templates are used to alert users and editors of important information. The table below gives a brief description of a few notices. For a full list of notice templates, see Category:Notices.

Template Description
{{attention}} Description ⚑
{{copyright}} Description
{{theory}} Description
{{spoilers}} Description
{{delete}} Description
{{move}} Description
{{attention}}
Makes note at top of page that article needs attention and categorizes the article accordingly. Place directly after infobox.
{{copyright}}
Asks users not to copy the content on the article.
{{theory}}
Warns that the article or section contains speculation and should not be considered canon. Place directly after infobox or directly after section heading.
{{spoilers}}
Warns that the article contains information pertaining to recently published material that many users may not have read yet. Place directly after infobox.
{{delete}}
Requests that an administrator delete the page.
{{move}}
Requests that an administrator move the page (change the title). An unnamed parameter may be included to indicate which page it should be moved to.
Quality Tags
Quality tags are simple templates that indicate the level of completion/quality of an article and categorize it accordingly. These are discussed in detail on the Help:Categories page and include {{stub}}, {{partial}}, and {{complete}}

Reference Templates

Reference templates are used to cite the source of information in an article. They create a superscript number that links to the footnotes in the "Notes" section, where the full reference is provided. For more on reference templates, see Help:References.

Link Macros

Link macros are templates which link to something that's related to the input. They often categorize the article as well. For a full list of link macros, see Category:Link macros.

Editorial Notations

Editorial notations are used to highlight information which is unsupported, ambiguous, or questionable. For more, see Help:References.

Other Templates

Some other notable templates include the following:

{{columns}}
Use the {{columns}} template to create columns. Use {{columns|count=N|TEXT}}, where N is the desired number of columns and TEXT is the content to be split up into columns. Separate items in TEXT by using line breaks or lists. Note that |count=N may be omitted; the number of columns is 3 by default.
This... ...produces:
{{columns|count=2|
* Item 1
* Item 2
* Item 3
* Item 4
* Item 5
}}
  • Item 1
  • Item 2
  • Item 3
  • Item 4
  • Item 5
{{quote}}
Use {{quote}} to highlight some text as a quote. Use {{quote|TEXT|SOURCE}}, where TEXT is the quote itself and SOURCE is the source of the quote (typically the name of the speaker or a short description of the context, followed by a reference). {{quote|Do or do not. There is no try.|Yoda}} produces:
“

Do or do not. There is no try. ”

—Yoda
{{for}}
This template provides a quick and clean way to refer to other articles. It generally takes one unnamed parameter, {{{1}}}, as input. By default, it returns "For more information, see {{{1}}}", where {{{1}}} is a link to the referenced article. A second unnamed parameter will replace "more information" and a third will replace the text which refers to the linked article. For example, {{for|cosmere|oodles of information|this page about the cosmere}} produces:


❮ Categories Templates What's Next? ❯