User:Lakrits/sandbox3: Difference between revisions

Jump to navigation Jump to search
-
(-)
(-)
Line 1: Line 1:
==Usage==
{{tlf|'''sp'''}} will insert a single, regular breaking space.
This template is especially useful when using [[Wikipedia:Help:Parser functions|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
* {{tlc|sp}}
==Examples==
===In parser functions===
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:
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>.}}
* {{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:
Inserted spaces in the examples below are coloured in <span style="color: #ffffff; background-color: #0095dd;">Firefox light blue</span> (see the [https://www.mozilla.org/en-US/styleguide/identity/firefox/color/ Mozilla Style guide]).
* {{samp|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 {{tlc|Linguist|latin{{=}}yes}}. Inserted spaces are coloured <span style="background-color: orange;">orange</span>.
====Adding a space using the space bar====
;<big>1. No additional space</big>
If the parameter {{para|latin}} is left out, i.e. the template is called with the code string {{tlc|Linguist}}, the output looks alright (see the table below).
 
However, if the template is called with the code string {{tlc|Linguist|latin{{=}}yes}}, and no space at all is included in the template code, the words "''Greek''" and "''and''" will be merged into "''Greekand''".
{| class="wikitable" style="background-color: white;"
! Template code !! {{para|latin|plain=yes}} invoked !! Output
|-
| rowspan="2" | {{code|He speaks Greek<nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.}} || {{no}} || {{samp|He speaks Greek.}}
|-
| {{yes}} || {{samp|He speaks Greekand Latin.}}
|}


;<big>Adding a space to the template</big>
;<big>2. Space inside function</big>
;1. No additional space
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.
If no space at all is included, the words ''Greek'' and ''and'' will be merged.
{| class="wikitable" style="background-color: white;"
{| border="0"
! Template code !! {{para|latin|plain=yes}} invoked !! Output
|-
| rowspan="2" | <code>He speaks Greek<nowiki>{{#if:{{{latin|}}}|</nowiki><span style="background-color: #0095dd;"> </span><nowiki>and Latin}}</nowiki>.</code> || {{no}} || {{samp|He speaks Greek.}}
|-
|-
| {{code|He speaks Greek<nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.}} || &nbsp;&nbsp;&rarr;&nbsp;&nbsp; || {{samp|He speaks Greekand Latin.}}
| {{yes}} || {{samp|He speaks Greekand Latin.}}
|}
|}


;2. Space inside function
;<big>3. Space outside function</big>
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.
If the space instead is placed outside the function, the template will work when including the sub-string. But, if {{para|latin}} is left out, this code will output a space between the last word and the full stop
{| border="0"
{| class="wikitable" style="background-color: white;"
! Template code !! {{para|latin|plain=yes}} invoked !! Output
|-
|-
| <code>He speaks Greek<nowiki>{{#if:{{{latin|}}}|</nowiki><span style="background-color: orange;"> </span><nowiki>and Latin}}</nowiki>.</code> || &nbsp;&nbsp;&rarr;&nbsp;&nbsp; || {{samp|He speaks Greekand Latin.}}
| rowspan="2" | <code>He speaks Greek<span style="background-color: #0095dd;"> </span><nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.</code> || {{no}} || <samp>He speaks Greek<span style="background-color: #0095dd;"> </span>.</samp>
|-
| {{yes}} || <samp>He speaks Greek<span style="background-color: #0095dd;"> </span>and Latin.</samp>
|}
|}


;3. Space outside function
====Adding a space using this template====
If the space instead is placed outside the function, the template will work when including the sub-string …
;<big>4. {{tlf|sp}} inside function</big>
{| border="0"
Using this template to add a space before the optional string (i.e. {{samp|<nowiki>{{sp}}</nowiki>and Latin}}), you will get the correct output both when leaving out {{para|latin}}, and when it's invoked.
{| class="wikitable" style="background-color: white;"
! Template code !! {{para|latin|plain=yes}} invoked !! Output
|-
| rowspan="2" | <code>He speaks Greek<nowiki>{{#if:{{{latin|}}}|</nowiki><span style="color: #ffffff; background-color: #0095dd;"><nowiki>{{sp}}</nowiki></span><nowiki>and Latin}}</nowiki>.</code> || {{no}} || {{samp|He speaks Greek.}}
|-
|-
| <code>He speaks Greek<span style="background-color: orange;"> </span><nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.</code> || &nbsp;&nbsp;&rarr;&nbsp;&nbsp; || <samp>He speaks Greek<span style="background-color: orange;"> </span>and Latin.</samp>
| {{yes}} || <samp>He speaks Greek<span style="background-color: #0095dd;"> </span>and Latin.</samp>
|}
|}


… but, if {{para|latin}} is left out, this code will output a space between the last word and the full stop:
==See also==
* <samp>He speaks Greek<span style="background-color: orange;"> </span>.</samp>
* {{tl|nbsp}}: Inserts (up to 25) non-breaking space characters.
* {{tl|space}}: Inserts any one of a number of different space characters.
3,860

edits

Navigation menu