Changes

Jump to: navigation, search

User:Lakrits/sandbox3

1,974 bytes added, 15:59, 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).* {{samp|He speaks Greek.}}ButHowever, we want to include the sub-string, so in the examples below, it is assumed that 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''". Inserted spaces are coloured <span {| class="wikitable" style="background-color: orangewhite;"! Template code !! {{para|latin|plain=yes}} invoked !! Output|-| rowspan="2" | {{code|He speaks Greek<nowiki>orange{{#if:{{{latin|}}}|and Latin}}</spannowiki>.}} || {{no}} || {{samp|He speaks Greek.}}|-| {{yes}} || {{samp|He speaks Greekand Latin.}}|}
;<big>Adding a space to the template2. Space inside function</big>;Including a space inside the function will give the same output as in example 1. No additional spaceIf no space at , since (as mentioned above) all is included, the words ''Greek'' leading and ''and'' will be mergedtrailing spaces are trimmed.{| borderclass="0wikitable"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.}}
|-
| {{code|He speaks Greek<nowiki>{{#if:{{{latin|yes}}}|and Latin}}</nowiki>.}} || &nbsp;&nbsp;&rarr;&nbsp;&nbsp; || {{samp|He speaks Greekand Latin.}}
|}
;2<big>3. Space inside outside function</big>Including a If the space inside instead is placed outside the function , the template will give work when including the same result as in example 1sub-string. But, if {{para|latin}} is left out, since (as mentioned above) all leading this code will output a space between the last word and trailing spaces are trimmed.the full stop{| borderclass="wikitable" style="0background-color: white;"! Template code !! {{para|latin|plain=yes}} 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: orange#0095dd;"> </span><nowiki>and Latin}}</nowiki>.</codesamp> |-| &nbsp;&nbsp;&rarr;&nbsp;&nbsp; {{yes}} || {{<samp|>He speaks Greekand Greek<span style="background-color: #0095dd;"> </span>and Latin.}}</samp>
|}
====Adding a space using this template====;3<big>4. Space outside {{tlf|sp}} inside function</big>If the Using this template to add a space instead is placed outside before the functionoptional string (i.e. {{samp|<nowiki>{{sp}}</nowiki>and Latin}}), you will get the template will work correct output both when leaving out {{para|latin}}, and when including the subit's invoked.{| class="wikitable" style="background-color: white;"! Template code !! {{para|latin|plain=yes}} invoked !! Output|-string …| rowspan="2" | <code>He speaks Greek<nowiki>{{#if:{{{latin| border}}}|</nowiki><span style="0color: #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|}yes}}|and Latin}}</nowiki>.</code> || &nbsp;&nbsp;&rarr;&nbsp;&nbsp; || <samp>He speaks Greek<span style="background-color: orange#0095dd;"> </span>and Latin.</samp>
|}
… but, if ==See also==* {{paratl|latinnbsp}} is left out, this code will output a : Inserts (up to 25) non-breaking space between the last word and the full stop:characters.* <samp>He speaks Greek<span style="background-color{{tl|space}}: orange;"> </span>Inserts any one of a number of different space characters.</samp>
3,860
edits

Navigation menu