Difference between revisions of "Template:Short"

From FollowTheScore
Jump to: navigation, search
m
 
(33 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}+5}}|{{#sub:{{{string|}}}|0|{{{count|25}}}}}{{{suffix| …}}}|{{{string|}}}}}</includeonly><noinclude>__NOTOC__
+
<includeonly>{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}{{#ifeq:{{{forcecount}}}|yes||+{{{tolerance|5}}}}}}}|{{#sub:{{{string|}}}|0|{{{count|25}}}}}{{{suffix| …}}}|{{{string|}}}}}</includeonly><noinclude>__NOTOC__
 
==The template==
 
==The template==
<pre>{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}+5}}|
+
<pre>{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}{{#ifeq:{{{forcecount}}}|yes||+{{{tolerance|5}}}}}}}
{{#sub:{{{string|}}}|0|{{{count|25}}}}}{{{suffix|}}}|
+
|{{#sub:{{{string|}}}|0|{{{count|25}}}}}{{{suffix| }}}
{{{string|}}}
+
|{{{string|}}}
 
}}</pre>
 
}}</pre>
  
 
==Usage==
 
==Usage==
This shortens strings. This can be used to shorten URLs or included text.<br>Note: Requires [http://www.mediawiki.org/wiki/Extension:StringFunctions Extension:StringFunctions].
+
This shortens text. It does ''not'' cut at a word boundary. Don't use this template for URLs. Use {{Templink|ShortLink}} instead.<br>To shorten included page content via DPL you can use <code>includemaxlength=[n]</code> in combination with <tt>[[Include#include|include]]</tt>.<br>Note: USing template on your own wiki requires [http://www.mediawiki.org/wiki/Extension:StringFunctions Extension:StringFunctions]
  
 
===Usage===
 
===Usage===
Line 14: Line 14:
 
|count  =
 
|count  =
 
|suffix =
 
|suffix =
 +
|tolerance  =
 +
|forcecount = (yes)
 
}}</pre>
 
}}</pre>
 
*'''count''': optional / default: 25
 
*'''count''': optional / default: 25
 
:The number of displayed characters (white space / blanks are counted).
 
:The number of displayed characters (white space / blanks are counted).
:It uses a tolerance of 5. So if you define count=10 the string will not be shortened if it is between 1 and 15 characters long.
+
:It uses a tolerance of 5. So if you define count=10 the string will not be shortened if it is between 1 and 15 characters long.  
*'''suffix''': optional / default: " …" (not ...)
+
*'''suffix''': optional / default: " …" (not " ...")
 +
:Adds an suffix at the end of the shortened string. Use a blank for none.
 +
*'''tolerance''': optional / default: 5
 +
:Override the default tolerance. The higher the count the more you should set the tolerance. This is useful to not shorten the last words of a 1000 character text.
 +
*'''forcecount''': optional / default: no
 +
:forcecount=yes overrides the (default) tolerance and forces a strict count.
  
 +
===Examples===
 +
<pre>{{Short|string=123456789|count=3}}</pre>
 +
Result: {{Short|string=123456789|count=3}}
 +
 +
<pre>{{Short|string=1 2 3 4 5 6 7 8 9|count=6|suffix=<-The end}}</pre>
 +
Result: {{Short|string=1 2 3 4 5 6 7 8 9|count=6|suffix=<-The end}}
 +
 +
<pre>|{{Short|string=abcdefghijkl|count=4|suffix= }}|</pre>
 +
Result: |{{Short|string=abcdefghijkl|count=4|suffix= }}|
 +
 +
<pre>{{Short|string=Has inconsideratus nauta effrenus, Algor infrunitus, inconcussus Rogo eo non Namucense,
 +
commissum, laureatus Scutum, de boo si anhelo Commoneo procellosus sono emitto Crimen agna.
 +
Si subo Accubo castimonia hic ibi qua lux sto eu Pulcher Sem. Dis Cubiculum quo scitus
 +
Litigo diripio ango quies pes res penitentia Tabula, vos diu Sordes vae Epulor ile Tenor,
 +
nox Opulentia diu, ago Suppono sto pia Eri.|count=250}}</pre>
 +
Result: {{Short|string=Oplastus Improviso cui te curvo. Eo privus ars Iussu infodio, ut se stipatores firmo, lac Decurro, fides Fruor, modio per opus Marceniense Cassus gestum volup diatesseron munio. Pulpa ac his simulo demens illum Ne archidictus, pes capistrum curo nam intolerabiliter Succumbo vis Effor per Algeo confingo. Fas me Prosper sol impleo quasi imago immarcescibilis multifluus Primordia fundo falsidicus corium, diurnitas humo pro leto. Sui Ueraciter hio eruca lenis qua Agalmate ut fors penitentia. Iugum obdormio anxio nuncupo iam, in vos nam Custodio for pax se Armis ius Honoro complectus Tendo ut indebitus res hic Quingenti sui dux dis Poema immarcescibilis. Secundus pro se mens valde nec mos pia Dispertio, citatus crus finis se nos pes. Sem res Caseus suo pulmentum Requiro fors tandem, revera iam.|count=250}}
 +
 +
<pre>{{Short|string=Abiliter Frustro quo Latro pax Ethologus nec ico ops Fabrico innotesco.|count=500|suffix=<-The end}}</pre>
 +
The string is shorter than the count. It will be fully returned without suffix.<br>Result: {{Short|string=Abiliter Frustro quo Latro pax Ethologus nec ico ops Fabrico innotesco.|count=500}}
 +
 +
<pre>{{Short|string=123456789|count=5}}</pre>
 +
The default tolerance of 5 returns the string unshortened (9 – 5 = <=5)<br>Result: {{Short|string=123456789|count=4}}
 +
 +
<pre>{{Short|string=123456789|count=5|forcecount=yes}}</pre>
 +
We force the count so it is shortened.<br>Result: {{Short|string=123456789|count=5|forcecount=yes}}
  
===Examples===
+
<pre>{{Short|string=123456789|count=5|tolerance=2}}</pre>
<pre>{{Short|string=The number of displayed characters (white space / blanks are counted).|count=40}}</pre>
+
We use a tolreance=2. Nothing special.<br>Result: {{Short|string=123456789|count=5|tolerance=2}}
'''Result:''' {{Short|string=The number of displayed characters (white space / blanks are counted).|count=40}}
 
  
<pre>{{Short|string=The number of displayed characters (white space / blanks are counted).|count=500}}</pre>
+
<pre>{{Short|string=123456789|count=7|tolerance=2}}</pre>
The sring short than the count, nothing happens:<br>'''Result:''' {{Short|string=The number of displayed characters (white space / blanks are counted).|count=500}}
+
We use a tolerance=2 and count=7.<br>Result: {{Short|string=123456789|count=7|tolerance=2}}
</noinclude>
 

Latest revision as of 06:25, 24 July 2009

The template

{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}{{#ifeq:{{{forcecount}}}|yes||+{{{tolerance|5}}}}}}}
|{{#sub:{{{string|}}}|0|{{{count|25}}}}}{{{suffix| …}}}
|{{{string|}}}
}}

Usage

This shortens text. It does not cut at a word boundary. Don't use this template for URLs. Use {{ShortLink}} instead.
To shorten included page content via DPL you can use includemaxlength=[n] in combination with include.
Note: USing template on your own wiki requires Extension:StringFunctions

Usage

{{Short
|string =
|count  =
|suffix =
|tolerance  =
|forcecount = (yes)
}}
  • count: optional / default: 25
The number of displayed characters (white space / blanks are counted).
It uses a tolerance of 5. So if you define count=10 the string will not be shortened if it is between 1 and 15 characters long.
  • suffix: optional / default: " …" (not " ...")
Adds an suffix at the end of the shortened string. Use a blank for none.
  • tolerance: optional / default: 5
Override the default tolerance. The higher the count the more you should set the tolerance. This is useful to not shorten the last words of a 1000 character text.
  • forcecount: optional / default: no
forcecount=yes overrides the (default) tolerance and forces a strict count.

Examples

{{Short|string=123456789|count=3}}

Result: Expression error: Unrecognized punctuation character "{".

{{Short|string=1 2 3 4 5 6 7 8 9|count=6|suffix=<-The end}}

Result: Expression error: Unrecognized punctuation character "{".

|{{Short|string=abcdefghijkl|count=4|suffix= }}|

Result: |Expression error: Unrecognized punctuation character "{".|

{{Short|string=Has inconsideratus nauta effrenus, Algor infrunitus, inconcussus Rogo eo non Namucense, 
commissum, laureatus Scutum, de boo si anhelo Commoneo procellosus sono emitto Crimen agna. 
Si subo Accubo castimonia hic ibi qua lux sto eu Pulcher Sem. Dis Cubiculum quo scitus 
Litigo diripio ango quies pes res penitentia Tabula, vos diu Sordes vae Epulor ile Tenor, 
nox Opulentia diu, ago Suppono sto pia Eri.|count=250}}

Result: Expression error: Unrecognized punctuation character "{".

{{Short|string=Abiliter Frustro quo Latro pax Ethologus nec ico ops Fabrico innotesco.|count=500|suffix=<-The end}}

The string is shorter than the count. It will be fully returned without suffix.
Result: Expression error: Unrecognized punctuation character "{".

{{Short|string=123456789|count=5}}

The default tolerance of 5 returns the string unshortened (9 – 5 = <=5)
Result: Expression error: Unrecognized punctuation character "{".

{{Short|string=123456789|count=5|forcecount=yes}}

We force the count so it is shortened.
Result: Expression error: Unrecognized punctuation character "{".

{{Short|string=123456789|count=5|tolerance=2}}

We use a tolreance=2. Nothing special.
Result: Expression error: Unrecognized punctuation character "{".

{{Short|string=123456789|count=7|tolerance=2}}

We use a tolerance=2 and count=7.
Result: Expression error: Unrecognized punctuation character "{".