User:Lakrits/sandbox3

From MozillaWiki
< User:Lakrits
Revision as of 03:07, 7 January 2015 by Lakrits (talk | contribs) (-)
Jump to navigation Jump to search

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

If the parameter |latin is left out, i.e. the template is called with the code string {{Linguist}}, the output looks alright:

  • He speaks Greek.

But, we want to include the sub-string, so in the examples below, it is assumed that the template is called with the code string {{Linguist|latin=yes}}. Inserted spaces are coloured orange.

Adding a space to the template
1. No additional space

If no space at all is included, the words Greek and and will be merged.

He speaks Greek{{#if:{{{latin|}}}|and Latin}}.   →   He speaks Greekand Latin.
2. Space inside function

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

He speaks Greek{{#if:{{{latin|}}}| and Latin}}.   →   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 …

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

… but, if |latin is left out, this code will output a space between the last word and the full stop:

  • He speaks Greek .