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
# wordwrap
148 lars 2
 
3
Wraps a string to a column width, the default is 80. As an optional
4
second parameter, you can specify a string of text to wrap the text to
5
the next line, the default is a carriage return `"\n"`. By default,
6
`wordwrap` will attempt to wrap at a word boundary. If you want to cut
7
off at the exact character length, pass the optional third parameter as
8
TRUE. This is equivalent to the PHP
991 lars 9
[`wordwrap()`](https://www.php.net/wordwrap) function.
148 lars 10
 
991 lars 11
## Basic usage
12
```smarty
13
{$myVar|wordwrap:30}
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 columns to wrap to.                                                  |
21
| 2                  | string  | No       | \\n     | This is the string used to wrap words with.                                                   |
22
| 3                  | boolean | No       | FALSE   | This determines whether to wrap at a word boundary (FALSE), or at the exact character (TRUE). |
148 lars 23
 
991 lars 24
## Examples
148 lars 25
 
991 lars 26
```php
27
<?php
148 lars 28
 
991 lars 29
$smarty->assign('articleTitle',
30
                "Blind woman gets new kidney from dad she hasn't seen in years."
31
               );
148 lars 32
 
991 lars 33
```
34
 
148 lars 35
Where template is
36
 
991 lars 37
```smarty
38
{$articleTitle}
148 lars 39
 
991 lars 40
{$articleTitle|wordwrap:30}
148 lars 41
 
991 lars 42
{$articleTitle|wordwrap:20}
148 lars 43
 
991 lars 44
{$articleTitle|wordwrap:30:"<br />\n"}
148 lars 45
 
991 lars 46
{$articleTitle|wordwrap:26:"\n":true}
47
```
148 lars 48
 
49
Will output:
50
 
991 lars 51
```html
52
Blind woman gets new kidney from dad she hasn't seen in years.
148 lars 53
 
991 lars 54
Blind woman gets new kidney
55
from dad she hasn't seen in
56
years.
148 lars 57
 
991 lars 58
Blind woman gets new
59
kidney from dad she
60
hasn't seen in
61
years.
148 lars 62
 
991 lars 63
Blind woman gets new kidney<br />
64
from dad she hasn't seen in<br />
65
years.
148 lars 66
 
991 lars 67
Blind woman gets new kidn
68
ey from dad she hasn't se
69
en in years.
70
```
148 lars 71
 
991 lars 72
See also [`nl2br`](language-modifier-nl2br.md) and
73
[`{textformat}`](../language-custom-functions/language-function-textformat.md).