More actions
bg3.wiki sidebar |
---|
Maintenance |
Help |
Policy |
Manuals |
A template is a special type of page designed to be transcluded within other pages. Templates allow editors to automatically insert frequently-used images, code, and formatting on a page.
To ensure standardised practices across the wiki, this page provides guidelines for the process of template creation.
Template documentation is essential component of template creation, and ensures templates are well understood and used correctly across the wiki.
To create or edit templates you need access to them. This can be requested on the Discord or by visiting an admin's talk page.
Template names
In order to ensure templates naming conventions are standardised across the wiki, all templates follow the same naming conventions.
Template page names
Template page names should be given in lower case letters with a single space between words.
Note that the first letter of a template page name will always be considered capitalised, including when the template is linked to or transcluded.
- Examples of good template page names
- {{cite text}}
- {{relative location}}
- {{spell page}}
Exceptions
Sometimes template names may consist of an abbreviation or a single word.
For example, {{reflist}} is named as such because it adds a <reference> tag to list references. If it had been named {{reference list}} the name would have implies it's a list of or for reference tags instead.
Similarly, certain abbreviated names for templates such as {{sai}}, {{ref}} and {{em}} are also considered acceptable, due to their simplicity.
Shortcuts
To make templates easier to use, each template should have 1-5 shortcuts. These are redirects which have shorter names for ease of access. These do not need to follow the template page naming conventions.
As few shortcuts as possible should be created in order to prevent ambiguity. It a single shortcut is sufficient, then additional shortcuts should not be created.
There are no precise standards for naming shortcuts, but they should ideally be intuitive and unambiguous.
Typically, a shortcut is considered reasonable if:
- It is an unambiguous abbreviation of the target template's name.
- It is more convenient to type than the full template name.
- It is closely associated with the template's function.
- Examples of shortcuts
- {{"}}, redirects to {{quote inline}}
- {{t link}}, redirects to {{template link}}
- {{cw}}, redirects to {{content warning}}
Template creation guidelines
Template creation is an essential part of the technical BG3Wiki workflow. However, it's important to take care when creating or improving templates.
What to keep in mind
Ideally, new templates should be:
- Easy to use, with as few parameters as possible.
- Have clear and easy to understand template documentation with examples.
- Always include a list of all of a template's shortcuts.
- Have easy to use TemplateData.
Important considerations
Some important considerations when creating templates:
- Line breaks interact unexpectedly with the table parser, which can break some templates.
- Adding a pipe to a template parameter {{{parameter}}} > {{{parameter|}}} will provide it with a default value (in this case, an empty string).
- This is important to remember when using the {{#if:}} parser function, since in cases where a parameter is undefined, {{{parameter}}} will return the value "true", whereas {{{parameter|}}} will return the value "false".
- It is also important to remember when a parameter is used as a value, since in cases where a parameter is undefined, {{{parameter}}} will return the value "{{{parameter}}}", whereas {{{parameter|}}} will return its default value (in this case, an empty string).
- Expr and ifeq, when evaluating numbers, produce different results. This is because expr treats numbers as floats, whereas ifeq treats them as integers.
Cargo database
Templates also allow the wiki to populate database tables with stored values using Cargo queries. This allows the wiki to create automatically generated lists of items or spells.
Formatting
- Templates must have "template data", achieved by clicking "Manage template data" at the top of the page. This enables templates to be used by visual editors.
- The template data must be on the template's main page if it does not have a doc subpage. It must be on the template's doc subpage if it does have one.
- Templates should have documentation that includes at least one example of its usage.
- Templates should use
{{documentation|content=}}
for all of its documentation.- Long documentation may be moved to a
/doc
subpage. In this case, use{{documentation}}
on the main page instead.
- Long documentation may be moved to a
- Templates must have categories. At the bare minimum, it should be categorized as Category:Templates or one of its subcategories.
- The categories should be located on the doc subpage, if it exists. The doc subpage must use
<noinclude>
tags around categories, otherwise the subpage will be counted as a template in the category index.
- The categories should be located on the doc subpage, if it exists. The doc subpage must use
- Cargo declare must be in a noinclude on the template's main page, even if there is a doc subpage.
Template documentation
Template documentation should ideally include the following:
- A description of what the template does.
- Examples of the template in use, either using {{comparison table}}, {{c}} and / or <pre></pre> tags.
- Clear descriptions of the template's parameters.
- Links to similar or relevant templates.
How to include documentation
The template itself should be placed within the tag <includeonly></includeonly>
. The template documentation should follow immediately after and should be placed within the tag <noinclude></noinclude>
and use Template:Documentation. Be careful not to leave any unnecessary whitespace or line breaks! Example:
<includeonly>Template here.</includeonly><noinclude>{{documentation|content=Template documentation here.}}</noinclude>
Examples can be written using either the {{code}} template and the <nowiki></nowiki> tag:
{{code|<nowiki>{{ExampleTemplate|ExampleParameter}}</nowiki>}}
Or by using well as the <pre>...</pre>
tag.
The code example should be followed by the actual template in use.
Templates that have very long documentation can move the documentation (including template data) to the /doc
subpage. The main page can simply contain <noinclude>{{documentation}}</noinclude>
. The /doc
subpage's contents will then automatically be transcluded on the template's page. Note that categories should remain on the main template page, still within the noinclude
tags.
Writing template data
TemplateData can be managed by via the Template Documentation Menu, which can be opened via the "Manage TemplateData" button located above the Source Editor:
TemplateData allows editors using the Visual Editor to easily add Templates to articles, but can also serve as an effective shorthand documentation for editors using the Source Editor.