3,860
edits
(-) |
(-) |
||
Line 1: | Line 1: | ||
Consider the mock template {{tlf|Linguist}}. It has a fixed string, "''He speaks Greek''", and an optional sub-string, "''and Latin''", which is included if the parameter {{para|latin}} is specified. The code for the template looks like this: | |||
* {{code|He speaks Greek<nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.}} | |||
If the parameter {{para|latin}} is left out, i.e. the template is called with the code string {{tlc|Linguist}}, the output looks alright: | |||
* {{samp|He speaks Greek.}} | |||
|} | |||
;<big>Adding a space to the template</big> | |||
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 {{tlc|Linguist|latin{{=}}yes}}. Inserted spaces are coloured orange. | |||
;1. No additional space | |||
If no space at all is included, the words ''Greek'' and ''and'' will be merged. | |||
{| border="0" | |||
|- | |||
| {{code|He speaks Greek<nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.}} || → || {{samp|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. | |||
{| border="0" | |||
|- | |||
| <code>He speaks Greek<nowiki>{{#if:{{{latin|}}}|</nowiki><span style="background-color: orange;"> </span><nowiki>and Latin}}</nowiki>.</code> || → || {{samp|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 … | |||
{| border="0" | |||
|- | |||
| <code>He speaks Greek<span style="background-color: orange;"> </span><nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.</code> || → || {{samp|He speaks Greek and Latin.}} | |||
|} | |||
… but, if {{para|latin}} is left out, this code will output a space between the last word and the full stop: | |||
* {{samp|He speaks Greek .}} |
edits