Wiktionary:Templates
- Main category: Templates
- For an index of the used templates, see Wiktionary:Template index.
| This is a Wiktionary policy, guideline or common practices page. Specifically it is a policy think tank, working to develop a formal policy. | |
| Policies – Entries: CFI - EL - NORM - NPOV - QUOTE - REDIR - DELETE. Languages: LT - AXX. Others: BLOCK - BOTS - VOTES. |
A template is a page in the Template namespace, which contains special wiki code that allows it to be reproduced on many different pages, via transclusion.
Templates help maintain consistent formatting and aid navigation between entries. They often include optional and/or variable elements controlled by parameters to allow for specialized use. Templates are also used to assist in a large variety of maintenance tasks. Each template has a matching Template talk: page where editors can discuss the design and implementation of the associated template.
Wiktionary makes heavy use of templates, so it is a good idea to familiarise yourself with how they work and how to use them, even if you don't write your own.
Internal links to template pages may be made by using the Template: prefix, e.g. [[Template:en-noun]].
Writing templates
Templates may either use a Scribunto module as underlying mechanism, or be written directly in template code. Although Scribunto is strongly preferred for templates with complex logic, a straightforward string-assembly template probably doesn't need a module. Some templates may also mix both, calling on Scribunto for some parts while using template/wiki code for the remainder.
Guides
The introductionary explanations of the sister project Wikipedia are of great help for beginners:
The sister project MediaWiki has several guides going in more depth for using and writing templates:
- mw:Help:Template
- mw:Help:Extension:ParserFunctions
- mw:Help:Section/Editing sections of included templates
- mw:Help:Magic words
- mw:Manual:Advanced templates
- mw:Manual:Representing arrays
If you wish to create a new template and are still inexperienced with them or with Wiktionary in general, ask for help at the technical community board on the WT:Grease Pit.
Maybe there isn't really a need for such a template, because the problem you are trying to solve with it can be approached differently. Maybe someone else already wrote something similar to your idea; it would be better to use what already exists instead of doing it all over again. For that reason, the best way to "learn" templates is probably to study the ones we already have on Wiktionary.
Language-specific templates
Many languages have their own set of templates, which can be found in one of the subcategories of Category:Templates by language. Language-specific templates are better able to cater to the needs of a specific language than a general template can, and allow for specific exceptions or restrictions that general templates don't. Because they are made for a specific language, knowledge of that language's grammar can be embedded into them. For example, the template {{es-conj}} automatically generates a table with a full set of inflected forms of a Spanish verb, while {{en-noun}} is capable of automatically showing the plural form of many English nouns.
While it may be easier to use generic templates like {{head}} to start off with, you'll eventually come to a point where it's better to create a tailor-made set of templates for your language. At that point, however, you'll already have all the "old" entries to deal with, which still use the generic all-language templates, which you'll then have to fix. For that reason, it's encouraged to create at least a basic set of headword-line templates (see below) for each language, before you start to create entries in that language.
Naming templates
Try to use a name that is both short and descriptive. As a rule of thumb, the more often the template will be used, the more leeway there is in using a short name. Templates that are used only within other templates should have longer names, as they generally don't need to be used that often. If you can, try to avoid using characters outside the ASCII encoding (use only the Latin alphabet), so that everyone can easily type the template's name.
Templates that are intended specifically for one language should have a name that begins with that language's language code, followed by a hyphen. For example, {{en-verb}} is intended to be used for English entries, {{nl-adj form of}} for Dutch entries, {{fr-conj-auto}} for French entries, {{sl-decl-adj}} for Slovene, and so on. What follows after the code is up to the creator of the template, but there are certain naming conventions that are followed, on which more below. If you are writing a template for a specific language, you include any of the characters that are used in that language as part of the name. However, even then, using just the Latin alphabet is preferable.
By convention, templates with specific types have names beginning with a prefix, followed in most cases by a language code and then another colon, and then a short, descriptive name. A small number of templates may be applicable across multiple languages and may omit the language code. These types are shown at the table below.
| Type | Name prefix | Example | Notes |
|---|---|---|---|
| General | — | {{en-noun}}
|
General templates are named with the language code followed by a dash (-).
|
| Reference templates | R:
|
{{R:hu:Zaicz 2021}}
|
|
| Quotation templates | RQ:
|
{{RQ:Atlantic}}
|
|
| Usage note templates | U:
|
{{U:en:less and fewer}}
|
|
| List templates | list:
|
{{list:Latin script letters/en}}
|
Language codes are after the description, after a "/" |
| Auto-table templates | table:
|
{{table:chess pieces/en}}
|
Changing existing templates
Special care should be taken when making changes to an existing template, since the changes will (potentially) affect all pages that transclude the template. Depending on the editing interface you are using, you should be able to preview your changes before publishing them (in the standard editor the relevant features are called "Show preview" and "Show changes"). You may also be able to preview (before publishing) how another page that calls the template you are editing will look once your changes are applied ("Preview page with this template").
Most of our templates can be modified by any user, but sometimes templates are protected from editing by regular users. In such a case, proposed changes can be discussed on the template's associated discussion page or in Wiktionary:Grease pit to gain consensus before requesting that the changes be made by a template editor.
