Template:Sp

From MozillaWiki
Jump to: navigation, search
Documentation icon Template documentation[view] [edit] [history] [purge]

Usage

{{sp}} will insert a single, regular breaking space.

This template is especially useful when using parser functions, and you need to insert a space at the beginning or end of an optional string. Any space character at these positions, inserted using the space bar, is automatically trimmed. Use this template if you want the space to appear in the output.

Parameters

There are no parameters.

Syntax

The template's syntax is

  • {{sp}}

Examples

In parser functions

Consider the mock template {{Linguist}}. It has a fixed string, "He speaks Greek", and an optional sub-string, "and Latin", which is included if the parameter |latin is specified. The code for the template looks like this:

  • He speaks Greek{{#if:{{{latin|}}}|and Latin}}.

Inserted spaces in the examples below are coloured in Firefox light blue (see the Mozilla Style guide).

Adding a space using the space bar

1. No additional space

If the parameter |latin is left out, i.e. the template is called with the code string {{Linguist}}, the output looks alright (see the table below).

However, if the template is called with the code string {{Linguist|latin=yes}}, and no space at all is included in the template code, the words "Greek" and "and" will be merged into "Greekand".

Template code "latin" invoked Output
He speaks Greek{{#if:{{{latin|}}}|and Latin}}. No He speaks Greek.
Yes He speaks Greekand Latin.
2. Space inside function

Including a space inside the function will give the same output as in example 1, since (as mentioned above) all leading and trailing spaces are trimmed.

Template code "latin" invoked Output
He speaks Greek{{#if:{{{latin|}}}| and Latin}}. No He speaks Greek.
Yes He speaks Greekand Latin.
3. Space outside function

If the space instead is placed outside the function, the template will work when including the sub-string. But, if |latin is left out, this code will output a space between the last word and the full stop.

Template code "latin" invoked Output
He speaks Greek {{#if:{{{latin|}}}|and Latin}}. No He speaks Greek .
Yes He speaks Greek and Latin.

Adding a space using this template

4. {{sp}} inside function

If you use this template to add a space before the optional string (i.e. {{sp}}and Latin), you will get the correct output both when leaving out |latin, and when it's invoked.

Template code "latin" invoked Output
He speaks Greek{{#if:{{{latin|}}}|{{sp}}and Latin}}. No He speaks Greek.
Yes He speaks Greek and Latin.

Limitations

Wiki pre-formatting markup

Any string or group of strings indented by a single space character will be pre-formatted and displayed in a box.

Example

If you enter the code:

 This text is pre-formatted.

the output will be:

This text is pre-formatted.

By using this template, you can override this function, but to no avail. Any inserted leading space characters from {{sp}} will simply be trimmed, leaving any text looking normal and aligned firmly to the left.

Example

If you write:

{{sp}}This text is pre-formatted.

the output will simply be:

This text is pre-formatted.

See also

  • {{nb}}: Inserts up to 10 non-breaking space characters.
  • {{space}}: Inserts any one of a number of different space characters.