| Zeile 1... |
Zeile -... |
| 1 |
truncate {#language.modifier.truncate}
|
- |
|
| 2 |
========
|
1 |
# truncate
|
| Zeile 3... |
Zeile 2... |
| 3 |
|
2 |
|
| 4 |
This truncates a variable to a character length, the default is 80. As
|
3 |
This truncates a variable to a character length, the default is 80. As
|
| 5 |
an optional second parameter, you can specify a string of text to
|
4 |
an optional second parameter, you can specify a string of text to
|
| 6 |
display at the end if the variable was truncated. The characters in the
|
5 |
display at the end if the variable was truncated. The characters in the
|
| 7 |
string are included with the original truncation length. By default,
|
6 |
string are included with the original truncation length. By default,
|
| 8 |
`truncate` will attempt to cut off at a word boundary. If you want to
|
7 |
`truncate` will attempt to cut off at a word boundary. If you want to
|
| 9 |
cut off at the exact character length, pass the optional third parameter
|
8 |
cut off at the exact character length, pass the optional third parameter
|
| Zeile -... |
Zeile 9... |
| - |
|
9 |
of TRUE.
|
| - |
|
10 |
|
| - |
|
11 |
## Basic usage
|
| - |
|
12 |
```smarty
|
| - |
|
13 |
{$myVar|truncate:40:"..."}
|
| - |
|
14 |
```
|
| - |
|
15 |
|
| 10 |
of TRUE.
|
16 |
## Parameters
|
| 11 |
|
17 |
|
| 12 |
Parameter Position Type Required Default Description
|
18 |
| Parameter Position | Type | Required | Default | Description |
|
| 13 |
-------------------- --------- ---------- --------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
19 |
|--------------------|---------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 14 |
1 integer No 80 This determines how many characters to truncate to.
|
20 |
| 1 | integer | No | 80 | This determines how many characters to truncate to. |
|
| 15 |
2 string No \... This is a text string that replaces the truncated text. Its length is included in the truncation length setting.
|
21 |
| 2 | string | No | \... | This is a text string that replaces the truncated text. Its length is included in the truncation length setting. |
|
| 16 |
3 boolean No FALSE This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE.
|
22 |
| 3 | boolean | No | FALSE | This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE. |
|
| - |
|
23 |
| 4 | boolean | No | FALSE | This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE. Note that if this setting is TRUE, then word boundaries are ignored. |
|
| 17 |
4 boolean No FALSE This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE. Note that if this setting is TRUE, then word boundaries are ignored.
|
24 |
|
| - |
|
25 |
## Examples
|
| 18 |
|
26 |
|
| 19 |
|
27 |
```php
|
| 20 |
<?php
|
- |
|
| 21 |
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
- |
|
| 22 |
?>
|
28 |
<?php
|
| Zeile 23... |
Zeile 29... |
| 23 |
|
29 |
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
| Zeile 24... |
Zeile 30... |
| 24 |
|
30 |
```
|
| 25 |
|
31 |
|
| 26 |
where template is:
|
32 |
where template is:
|
| 27 |
|
33 |
|
| 28 |
|
34 |
```smarty
|
| 29 |
{$articleTitle}
|
35 |
{$articleTitle}
|
| 30 |
{$articleTitle|truncate}
|
36 |
{$articleTitle|truncate}
|
| 31 |
{$articleTitle|truncate:30}
|
37 |
{$articleTitle|truncate:30}
|
| 32 |
{$articleTitle|truncate:30:""}
|
38 |
{$articleTitle|truncate:30:""}
|
| 33 |
{$articleTitle|truncate:30:"---"}
|
- |
|
| 34 |
{$articleTitle|truncate:30:"":true}
|
39 |
{$articleTitle|truncate:30:"---"}
|
| Zeile 35... |
Zeile 40... |
| 35 |
{$articleTitle|truncate:30:"...":true}
|
40 |
{$articleTitle|truncate:30:"":true}
|
| Zeile 36... |
Zeile 41... |
| 36 |
{$articleTitle|truncate:30:'..':true:true}
|
41 |
{$articleTitle|truncate:30:"...":true}
|
| 37 |
|
42 |
{$articleTitle|truncate:30:'..':true:true}
|
| 38 |
|
43 |
```
|
| 39 |
|
44 |
|
| 40 |
This will output:
|
45 |
This will output:
|
| 41 |
|
46 |
|
| 42 |
|
47 |
```
|
| 43 |
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
48 |
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
| 44 |
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
49 |
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
| 45 |
Two Sisters Reunite after...
|
50 |
Two Sisters Reunite after...
|