Changes

Jump to: navigation, search

User:Lakrits/sandbox3

1,844 bytes added, 02:55, 7 January 2015
-
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>.}} || &rarr; || {{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> || &rarr; || {{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> || &rarr; || {{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 .}}
3,860
edits

Navigation menu