Changes

Jump to: navigation, search

User:Lakrits/sandbox3

4,816 bytes removed, 23:23, 7 January 2015
-
==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:
* {{code|He speaks Greek<nowiki>{{#if:{{{latin|}}}|and Latin}}</nowiki>.}}
 
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 !! "{{samp|latin}}" 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>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 !! "{{samp|latin}}" 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 !! "{{samp|latin}}" invoked !! Output
|-
| 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>
If you use 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 !! "{{samp|latin}}" 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>
|}
 
===Limitations===
;<big>Wiki pre-formatting markup</big>
Any string or group of strings indented by a single space character will be pre-formatted and displayed in a box.
 
;Example
If you enter the code:
 
<code><span style="color: #ffffff; background-color: #0095dd;">&nbsp;</span>This text is pre-formatted.</code>
 
the output will be:
 
This text is pre-formatted.
 
By using this template, you can override this function, but to no avail. Any inserted leading space characters from {{tlf|sp}} will simply be trimmed, leaving any text looking normal and aligned firmly to the left.
 
;Example
If you write:
 
<code><span style="color: #ffffff; background-color: #0095dd;"><nowiki>{{sp}}</nowiki></span>This text is pre-formatted.</code>
 
the output will simply be:
 
&#32;This text is pre-formatted.
<!--
==See also==
* {{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