User:Nihiltres/Template syntax style

This is a short guide on how template syntax probably ought to be best laid out for readability. It's an obscenely minor issue, that, as with regional varieties of English, shouldn't ever be fought over; it isn't worth the time. That said, it's nice to be consistent, so this guide lays out a set of three acceptable, clean styles, and when they ought to be preferred.

Compact style
The compact style is very simple: it omits all unnecessary whitespace. It lends itself best to short template calls. It should usually be preferred when a template call includes unnamed parameters. It is also appropriate for template calls with exactly one parameter that is a named parameter, so long as that parameter is relatively short. If a parameter is very long, consider using the block style instead. For example:

10 cm Or:

Inline style
The inline style uses spaces to separate its parameters visually, improving readability for long inline template calls. It should be used for all inline template calls that do not use the compact style.

There should be exactly one space inserted before each pipe character, and no spaces between the pipe, parameter name, equals sign, or the start of the parameter value. There is no extra space after the end of a parameter value; this is redundant to the space before each pipe. For example:

Block style
The block style uses both spaces and linebreaks to separate its parameters visually. It is the clearest template layout, but it is bulky and impractical for use in the middle of a paragraph. Therefore, it should be used only outside of paragraphs, where it would break their visual flow. For example, it is appropriate for infoboxes and lists.

The template name, template closure, and each individual parameter each are given their own line. Each parameter line should start with a pipe followed by a space, then the parameter name, a variable number of spaces, an equals sign, exactly one space, and then the parameter value. The variable number of spaces before the equals sign should be normalized so that each parameter line has an equal number of characters before its equals sign, and so that there is exactly one space between the longest parameter name and the equals sign. This lines up the template nicely when the edit field uses a monospace font. There should be no trailing whitespace on any line unless a parameter is empty, in which case one space following the equals sign is acceptable. There should not be any spaces or pipes before the template closure. For example:

Handling of nested templates
Sometimes templates are called inside of other template calls, e.g. citation templates in infobox fields. When templates that use the inline or block formats are nested in a template using the block format, they should also use the block format, with each parameter line, and the closing braces, indented by four spaces. For example:

Note that certain nested templates may require forms that require input to be placed at the beginning of a new line, e.g. the list formatting of plainlist input. In this case, indent consistently where possible. Even if it's inconsistent, if possible, indent the closing braces of a block-form nested template to distinguish them from the closing braces of the parent template.

Variant: paired parameters
Sometimes two or more parameters work closely together, e.g. the  and   parameters for author names. In that case, it's acceptable to place them on the same line for compactness, separated by a space instead of a newline. Both parameters on the same line should ignore the unified position for the equals sign, instead using the spacing style preferred by the inline style, except with a single space between the pipe and the start of the parameter name. For example:

Note that cite book should usually use the inline style except in lists of sources.

Variant: unnamed parameters
In the event that a template has one or more unnamed parameters that are very long, confusing, or span multiple lines, it's acceptable to use a variant block style, by replacing the spaces of the horizontal style with linebreaks. For example, the inline style example in this essay is formatted with a template like so:

