Difference between revisions of "Template:Short"

From FollowTheScore
Jump to: navigation, search
Line 1: Line 1:
<includeonly>{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}{{#ifeq:{{{forcecount}}}|yes||+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}}}{{#ifeq:{{{forcecount}}}|yes||+5}}}}
 
<pre>{{#ifexpr:{{#len: {{{string|}}} }} > {{#expr:{{{count|25}}}{{#ifeq:{{{forcecount}}}|yes||+5}}}}
Line 14: Line 14:
 
|count  =
 
|count  =
 
|suffix =
 
|suffix =
 +
|tolerance =
 +
|forcecount =
 
}}</pre>
 
}}</pre>
 
*'''count''': optional / default: 25
 
*'''count''': optional / default: 25
Line 19: Line 21:
 
: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.
 +
*'''tolerance''': optional / default: 5
 +
:Override the default tolerance.
 +
*'''forcecount''': optional
 +
: Override the (default) tolerance and use a strict count.
  
 
===Examples===
 
===Examples===
Line 26: Line 32:
  
 
<pre>{{Short|string=The number of displayed characters (white space / blanks are counted).|count=500}}</pre>
 
<pre>{{Short|string=The number of displayed characters (white space / blanks are counted).|count=500}}</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}}
+
The sring short than the count. It is fully returned without suffix:<br>'''Result:''' {{Short|string=The number of displayed characters (white space / blanks are counted).|count=500}}
 
</noinclude>
 
</noinclude>

Revision as of 18:48, 23 July 2009

The template

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

Usage

This shortens strings. This can be used to shorten URLs or included text.
Note: Requires Extension:StringFunctions

Usage

{{Short
|string =
|count  =
|suffix =
|tolerance =
|forcecount =
}}
  • 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.
  • tolerance: optional / default: 5
Override the default tolerance.
  • forcecount: optional
Override the (default) tolerance and use a strict count.

Examples

{{Short|string=The number of displayed characters (white space / blanks are counted).|count=40}}

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

{{Short|string=The number of displayed characters (white space / blanks are counted).|count=500}}

The sring short than the count. It is fully returned without suffix:
Result: Expression error: Unrecognized punctuation character "{".