Jump to content

Wikipedia:WikiProject User warnings/Help:Template coding

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pathoschild (talk | contribs) at 01:02, 17 January 2006 (Categorisation: added 'Optional decategorisation'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Wikipedia:WikiProject User warnings/t/documentation-header

General design guidelines

Template coding guidelines

Categorisation

  • User warning templates
    • User warning templates should be categorised to Category:User warning templates. If the template is a redirect page to another template, it should be categorised using the sort key "Redirect". The category tag should be on the template page within noinclude syntax.
      <noinclude>[[Category:User warning templates]]</noinclude>
      <noinclude>[[Category:User warning templates|Redirect]]</noinclude>
  • User block templates
    • User block templates should be categorised 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.
      <noinclude>[[Category:User block templates|Temporary]]</noinclude>
      <noinclude>[[Category:User block templates|Indefinite]]</noinclude>
  • Optional decategorisation
    • 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 <noinclude> 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: {{template|category=}}.
      <includeonly>{{category|[[Category:User block templates|Temporary]]}}</noinclude>

Parameters

  • Default values
    • Nearly all parameters should have a default value, such that misuse does not break the template; exceptions can be made for extra parameters. You can set the default value of a parameter by using piped syntax ({{{1|default value}}}). For example, the template below takes a parameter which expects the user to supply the proper pronoun (she, he, it, they, et cetera).

      {{{1|They}}} are cool.
      Supplied the pronoun with {{template|He}}, the template will expand to "He are cool" (grammar aside). Ignoring the parameter with {{template}}, the template will default the value and expand to "They are cool".
  • Expert syntax
    • Where use could conceivably include symbols that break templates (notably the pipe (|) and equals sign (=)), an Wikipedia:WikiProject User warnings/t/glossary should allow these. In such cases, an expert syntax and simple syntax can coexist as needed. For example, let us say we want to make a wikilink template.

      [[{{{1}}}]]

      Using {{template|article}} is straightforward enough, and will expand to [[article]]. A problem arises if the user tries to use certain symbols; for example, using {{template|article|name}} will not output [[article|name]], because the pipe symbol is part of the parameter Wikipedia:WikiProject User warnings/t/glossary. In cases where a user might conceivably want to use the template like this, the template can be modified to use expert syntax instead.

      [[{{{link}}}]]

      The template now uses a named parameter to get the user's input. Using {{template|link=article|name}} will now output [[article|name]], as long as the named parameter is specified after any unnamed parameter. However, it's not at all a one-or-the-other proposition; it's possible to allow both named and unnamed parameters at once. Using the same example, the below template will accept the simple syntax on all parameters except those for which the expert syntax is used.

      [[{{{link|{{{1}}}}}}]]

      Although this may look complex, it's relatively simple. The named parameter uses the unnamed parameter as the default value, such that if the expert syntax isn't used the simple syntax is. The unnamed parameter can be given a default value of it's own, which will be used if neither syntaxes are used.

      [[{{{link|{{{1|Main_page}}}}}}]]

      The above template used as {{template}}, {{template|article}}, and {{template|link=article|name}} will respectively output as [[Main_page]], [[article]], and [[article|name]].

Newlines and paragraphs

  • Compatibility with lists
    • All user warning templates should be natively compatible with lists. For optimal intervention efficiency, talk pages with numerous warnings are sometimes organised into formatted lists sectioned by date. Due to the way Wikipedia parses wikisyntax into HTML, list items are closed at any newline. Due to this, many templates 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 at 1. By using HTML paragraph syntax directly, Wikipedia's paragraph parsing is circumvented and multiple-paragraph templates can then be added to organised warning lists without problem.

      <p>Paragraph 1.</p><p>Paragraph 2.</p><p>Paragraph 3.</p>

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

      <p>Paragraph 1.</p><!--
      --><p>Paragraph 2.</p><!--
      --><p>Paragraph 3.</p>

Specific to block templates

  • CSS style
    • 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 box with the user-block class.

      <div class="user-block">template message</div>

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

      * .user-block { background:#C00; color:#FFF; }