aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/designers/language-modifiers/language-modifier-wordwrap.md
blob: 97cd774f773872fffa7e33328b96e838de87f244 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
wordwrap {#language.modifier.wordwrap}
========

Wraps a string to a column width, the default is 80. As an optional
second parameter, you can specify a string of text to wrap the text to
the next line, the default is a carriage return `"\n"`. By default,
`wordwrap` will attempt to wrap at a word boundary. If you want to cut
off at the exact character length, pass the optional third parameter as
TRUE. This is equivalent to the PHP
[`wordwrap()`](&url.php-manual;wordwrap) function.

   Parameter Position    Type     Required   Default  Description
  -------------------- --------- ---------- --------- ------------------------------------------------------------------------------------------------------
           1            integer      No        80     This determines how many columns to wrap to.
           2            string       No        \\n    This is the string used to wrap words with.
           3            boolean      No       FALSE   This determines whether or not to wrap at a word boundary (FALSE), or at the exact character (TRUE).


    <?php

    $smarty->assign('articleTitle',
                    "Blind woman gets new kidney from dad she hasn't seen in years."
                   );

    ?>

       

Where template is


    {$articleTitle}

    {$articleTitle|wordwrap:30}

    {$articleTitle|wordwrap:20}

    {$articleTitle|wordwrap:30:"<br />\n"}

    {$articleTitle|wordwrap:26:"\n":true}

       

Will output:


    Blind woman gets new kidney from dad she hasn't seen in years.

    Blind woman gets new kidney
    from dad she hasn't seen in
    years.

    Blind woman gets new
    kidney from dad she
    hasn't seen in
    years.

    Blind woman gets new kidney<br />
    from dad she hasn't seen in<br />
    years.

    Blind woman gets new kidn
    ey from dad she hasn't se
    en in years.

       

See also [`nl2br`](#language.modifier.nl2br) and
[`{textformat}`](#language.function.textformat).