Help:Templates

From bg3.wiki
Revision as of 14:01, 20 January 2024 by Willowisp (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This article is a technical guide to the creation of templates on BG3Wiki. For a guide on how to use templates, see Help:Using templates. See Help:List of templates for a list of templates.

Bgwiii.png IndexGuidesModdingDiscord

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[edit | edit source]

In order to ensure templates naming conventions are standardised across the wiki, all templates follow the same naming conventions.

Template page names[edit | edit source]

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

Exceptions[edit | edit source]

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[edit | edit source]

To make templates easier to use, each template should have 1-5 shortcuts, added with {{shortcut}}. 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

Template creation guidelines[edit | edit source]

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[edit | edit source]

Ideally, new templates should be:

  1. Easy to use, with as few parameters as possible.
  2. Have clear and easy to understand template documentation with examples.
  3. Always include a list of all of a template's shortcuts.
  4. Have easy to use TemplateData.

Important considerations[edit | edit source]

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.

Formatting[edit | edit source]

  • 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.
  • 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.
  • Cargo declare must be in a noinclude on the template's main page, even if there is a doc subpage.

Template documentation[edit | edit source]

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[edit | edit source]

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[edit | edit source]

For a thorough guide to TemplateData, see Information about TemplateData

TemplateData can be managed by via the Template Documentation Menu, which can be opened via the "Manage TemplateData" button located above the Source Editor:

A screenshot of the Manage TemplateData button which is 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.

Cargo database[edit | edit source]

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.

Additional resources[edit | edit source]