3,860
edits
(-) |
(-) |
||
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]). | ||
====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> | ;<big>2. Space inside function</big> | ||
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. | |||
{| 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="background-color: #0095dd;"> </span><nowiki>and Latin}}</nowiki>.</code> || {{no}} || {{samp|He speaks Greek.}} | |||
|- | |- | ||
| {{ | | {{yes}} || {{samp|He speaks Greekand Latin.}} | ||
|} | |} | ||
; | ;<big>3. Space outside function</big> | ||
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 | |||
{| | {| 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: | | 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> | |||
|} | |} | ||
; | ====Adding a space using this template==== | ||
;<big>4. {{tlf|sp}} inside function</big> | |||
{| | 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.}} | |||
|- | |- | ||
| | | {{yes}} || <samp>He speaks Greek<span style="background-color: #0095dd;"> </span>and Latin.</samp> | ||
|} | |} | ||
==See also== | |||
* | * {{tl|nbsp}}: Inserts (up to 25) non-breaking space characters. | ||
* {{tl|space}}: Inserts any one of a number of different space characters. |
edits