User:Lakrits/sandbox3: Difference between revisions

-
(-)
(-)
 
(32 intermediate revisions by the same user not shown)
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:
<table style="border: 0px none transparent;">
* {{code|He speaks Greek<nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.}}
<tr style="font-weight: bold;">
 
<td>{{{1}}}</td>
If the parameter {{para|latin}} is left out, i.e. the template is called with the code string {{tlc|Linguist}}, the output looks alright:
</tr>
* {{samp|He speaks Greek.}}
<tr style="margin-bottom: 0.75em;">
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 <span style="background-color: orange;">orange</span>.
<td style="width: 200px; margin-right: 1em; text-indent: 1.63em; font-style: italic;">{{{2}}}</td>
 
<td>{{{3}}}</td>
;<big>Adding a space to the template</big>
</tr>
;1. No additional space
</table>
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>.}} || &nbsp;&rarr;&nbsp; || {{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> || &nbsp;&rarr;&nbsp; || {{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> || &nbsp;&rarr;&nbsp; || {{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