Help:Templates: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(→‎Template creation: add a section of directives)
Line 31: Line 31:


=== Formatting ===
=== 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.
* Templates {{em|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.
** The template data {{em|must}} be on the template's main page if it does not have a doc subpage. It {{em|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 {{em|should}} have documentation that includes at least one example of its usage.  
* Templates '''should''' use {{c|<nowiki>{{documentation|content=}}</nowiki>}} for all of its documentation.
* Templates {{em|should}} use {{c|<nowiki>{{documentation|content=}}</nowiki>}} for all of its documentation.
** Long documentation '''may''' be moved to a {{c|/doc}} subpage. In this case, use {{c|<nowiki>{{documentation}}</nowiki>}} on the main page instead.
** Long documentation {{em|may}} be moved to a {{c|/doc}} subpage. In this case, use {{c|<nowiki>{{documentation}}</nowiki>}} 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.
* Templates {{em|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 {{c|<nowiki><noinclude></nowiki>}} tags around categories, otherwise the subpage will be counted as a template in the category index.
** The categories {{em|should}} be located on the doc subpage, if it exists. The doc subpage {{em|must}} use {{c|<nowiki><noinclude></nowiki>}} 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.
* Cargo declare {{em|must}} be in a noinclude on the template's main page, even if there is a doc subpage.


== Additional resources==
== Additional resources==

Revision as of 12:38, 1 December 2023

Bgwiii.png IndexGuidesModdingDiscord

This article is a technical guide to the use 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.

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. We use templates extensively on BG3Wiki, as they allow the use of easily accessible and consistent design, layout and formatting.

Template creation

Template creation is an essential part of the technical BG3Wiki workflow. However, it's important to take care when creating or improving templates.

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.

What to keep in mind

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. 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.

Template documentation

Template creators are encouraged to document (on the template's page itself as well as via the TemplateData button on the same page) how to use that template, including usage examples and accepted values for any template parameters. If you're unfamiliar with a particular template, navigate to its page to learn how it works. If a template page does not show any usage instructions, it could still be a work in progress, and you may want to check with its creator before using it.

See All Pages (Template namespace) for a full list of available templates on bg3.wiki.

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.
  • 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.

Additional resources