Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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