Help:Templates: Difference between revisions
| Line 99: | Line 99: | ||
=== Information Boxes === | === 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.) | 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., {{t|book}}, {{t|character}}, {{t|location}}), but there are a few other more specialized ones. | ||
{{for|Help:Infoboxes|more details on Infoboxes|post=For a list of available infobox templates, see [[:Category:Infoboxes]]}} | {{for|Help:Infoboxes|more details on Infoboxes|post=For a list of available infobox templates, see [[:Category:Infoboxes]]}} | ||
Revision as of 02:25, 21 March 2025
| 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 built in, 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. 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.INPUTwould be replaced by your input.
- Unnamed Parameters
- Unnamed parameters should be completely replaced by your input. For example:
{{template name|INPUT}}
- In this example
INPUTis 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 makes use of 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''
}}
|
|
| Example: Unnamed Parameters | |
|---|---|
This example makes use of 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}}
|
|
| Example: Mix of Parameters | |
|---|---|
This example makes use of 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=center|width=200px}}
|
|
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.
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. Common examples include {{Cosmere}}, {{Stormlight}}, and {{Reckoners}}.
For a full list of navbox templates, see Category:Navbars.
Notices
Notice templates alert users and editors of important information regarding the page itself. Some notable notice templates are listed below. For a full list of notice templates, see Category:Notices.
{{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
{{incomplete}},{{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:
{{b}}- This is a simple template that outputs a full book or series title given an abbreviated or shorthand reference. For example, "
{{b|sa1}}" returns "The Unselected Journals of Emma M. Lion: Volume 1"
{{columns}}- Use the
{{columns}}template to create columns. Use{{columns|count=N|TEXT}}, whereNis the desired number of columns andTEXTis the content to be split up into columns. Separate items inTEXTby using line breaks or lists. Note that|count=Nmay 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}}, whereTEXTis the quote itself andSOURCEis 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. ”
{{sidequote}}- Template:Sidequote Use
{{sidequote}}to place a quote on one side of the page, with text floating around it. Use{{sidequote|TEXT|SOURCE|POSITION|WIDTH}}, whereTEXTis the quote itself,SOURCEis the source of the quote,POSITIONis the alignment of the quote (leftorright), andWIDTHis some number followed by "px", to specify the width of the quote in pixels. When placed at the top of this paragraph,{{sidequote|Do or do not. There is no try.|Yoda|side=right|size=300px}}produces the quote to the right.
{{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:
Editing Templates
Editing templates (or creating one from scratch) is definitely not a task for beginners. But we'll go over some of the basics.
Includeonly and Noinclude
<includeonly>Tag- Everything you want the template to do when used on other pages should be sandwiched between
<includeonly>and</includeonly>tags.
<noinclude>Tag- The template's documentation, and anything else you want to show up on the template page itself, must be sandwiched between
<noinclude>and</noinclude>tags.
Parameters
- Named Parameters
- Named parameters are referred to by their name in triple braces. For example, the named parameter "books" in the
{{character}}template is referred to as{{{books}}}.
- Unnamed Parameters
- Unnamed parameters are referred to by the order they are entered. For example, the first unnamed parameter that is entered in the
{{book ref}}template is referred to as{{{1}}}, while the second is referred to as{{{2}}}.
- Defaults
- Provide a default value for parameters by including a vertical bar (
|) 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{{{1|Sanderson}}}.
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 MediaWiki's Parser Functions page. Here are some of the basics:
- Uppercasing Text
- This function converts a string of text to all uppercase.
- Use:
{{uc: TEXT}}, whereTEXTis the text to be converted. - Example:
{{uc: heLLo}}producesHELLO.
- Lowercasing Text
- This function converts a string of text to all lowercase.
- Use:
{{lc: TEXT}}, whereTEXTis the text to be converted. - Example:
{{lc: heLLo}}produceshello.
- String Compare
- This function compares two strings of text and provides one of two results.
- Use:
{{#ifeq: A|B|Result1|Result2}}, whereAandBare the strings of text. IfA=BthenResult1is returned; otherwise,Result2is returned. - Example:
{{#ifeq: dog|dog|same|different}}producessameand{{#ifeq: dog|cat|same|different}}producesdifferent.
- If-Then
- This function checks if a parameter exists and provides one of two results.
- Use:
{{#if: A|Result1|Result2}}, whereAis some parameter. IfAexists (i.e. it isn't null) thenResult1is returned; otherwise,Result2is returned. - Example: If a second unnamed parameter is provided,
{{#if: {{{2|}}}|hello|goodbye}}produceshello. If not, it producesgoodbye.
- Case-Switch
- This function performs a series of string compares until a "true" result is found.
- Use:
{{#switch: X|A=Result1|B=Result2|C=Result3|etc.|Default}}, whereXis compared toA,B, and so on. The first match provides the corresponding result. A final, default result may be provided in case no match is found. - Example:
{{#switch: cat|dog=bark|cat=meow|growl}}producesmeowand{{#switch: bear|dog=bark|cat=meow|growl}}producesgrowl.
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 MediaWiki's Magic Words page. The two most common are:
- Pagename
{{PAGENAME}}provides the name of the page/article. If used in this page it would yieldTemplates.
- Namespace
{{NAMESPACE}}provides the name of the page's namespace. If used in this page it would yieldHelp.
Comments
Comments inside of <includeonly> tags can be provided between <!-- and -->.
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 |- and the first cell |, which means the infobox {{row/kv}} (et al) can be nicely spaced without consequence.
| ❮ Categories | Templates | What's Next? ❯ |

