Wikipedia:WikiProject User warnings/Help:Template coding

Severity levels
Every series of templates includes four templates of increasing severity, designating a tone ranging from kindly to stern. These don't necessarily designate a chronological order; a user may simply use a level of his choice based on the severity desired. For example, the test series is test1, test2, test3, test4.
 * 1) Assumes the user is not malicious; welcome with polite pointer to sandbox and/or to relevant help and policy pages.
 * 2) No faith assumption; pointer to sandbox with polite request to stop and mention of consequences.
 * 3) Assumes bad faith; stern cease and desist.
 * 4) Assumes bad faith; strong cease and desist, last warning.

Civility
Regardless of the severity level of the template, the user warning should be a model of civility (even for the most destructive vandal). Remember than when you use a warning template, you do so in Wikipedia's name. See Please do not bite the newcomers, Civility, and Etiquette.

Derivatives
No derivative template (a non-standard variant of a template under a new name) should be included in the list of standardized templates or mentioned in the documentation. Although users are free to create and use non-standard templates, these should not be recognized by the project.

Template page
User warning templates should be categorized to Category:User warning templates (if the template is a redirect page to another template, it should be categorized using the sort key "Redirect"). User block templates should be categorized to Category:User block templates, with the sort key "Temporary" or "Indefinite" as appropriate. The category tag should be on the template page within noinclude syntax.

User talk page
Any template that places pages it's used on into a category should surround the category tags with the category parameter. If the template uses  tags, be careful to place the parameter inside these tags. This allows the use of the template on a page (such as a talk or list page) without adding that page to a category by using the template with no value specified for the category parameter:.

Default values
Nearly every parameter should have a default value, such that misuse does not break the template. You can set the default value of a parameter by using piped syntax. For example, the template below takes a parameter which expects the user to supply the proper pronoun. is cool.

Supplied the pronoun with, the template will expand to "He is cool". Ignoring the parameter with, the template will default the value and expand to "He or she is cool".

Named syntax
When a template's parameters might be given symbols that break templates (notably the '|' pipe symbol and '=' equals sign), a named syntax should allow these. In such cases, a named and unnamed can coexist as needed. For example, a wikilink template can assign both a name and a number to a parameter by 'nesting' them (placing parameters in other parameters' default values).

{{{1|{{{default value}}}}}}

Using  is straightforward enough, and will expand to. However, some symbols will break the template if used like that. These require the named syntax:, which will expand to.

Nested substitution
Any template containing templates, magic variables, or ParserFunctions should include a "safesubst:" parameter at the appropriate location. This allows for easy substitution of all nested templates inside a template. For example, consider the following template code:

Substituting the template using  will output "This is 2024".

Block template CSS
Wikipedia allows registered users to maintain a personal stylesheet located at user:username/skin.css, where 'username' is the username and 'skin' is the name of the skin in use (usually monobook). To help users take full advantage of this feature, block templates should be enclosed in a CSS container with the "user-block" class.

Should the user wish to, they can customize the appearance of all block templates by adding CSS to their user stylesheet. For example, the following code adds a dark red background with white text.

Compatibility with lists
All user warning and block templates should be natively compatible with lists. For optimal intervention efficiency, talk pages with numerous warnings are sometimes organized into formatted lists sectioned by date (see the guidelines). Due to the way Wikipedia parses wiki syntax into HTML, list items are closed at any newline.

Templates with newlines will break any list they are placed in: the first paragraph will be in the list, the others out, and any subsequent templates in the list will begin a new list. By using HTML paragraph syntax directly, Wikipedia's paragraph parsing is circumvented and multiple-paragraph templates can then be added to organized warning lists without problem. Paragraph 1. Paragraph 2. Paragraph 3.

To prevent the problem with newlines, templates must be on a single code line; however, this is highly illegible to humans in edit view. To restore legibility, HTML comments can be inserted to emulate the appearance of newlines. Although this looks ungainly with two-term lines, the comments are much less bulky when used with more realistic paragraphs. Paragraph 1. Paragraph 2. Paragraph 3.