2023-02-06 14:42:31 +01:00
|
|
|
# nl2br
|
2021-12-03 11:59:22 +01:00
|
|
|
|
|
|
|
All `"\n"` line breaks will be converted to html `<br />` tags in the
|
|
|
|
given variable. This is equivalent to the PHP\'s
|
2023-02-03 22:31:59 +01:00
|
|
|
[`nl2br()`](https://www.php.net/nl2br) function.
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
## Basic usage
|
|
|
|
```smarty
|
|
|
|
{$myVar|nl2br}
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
## Examples
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
```php
|
|
|
|
<?php
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
$smarty->assign('articleTitle',
|
|
|
|
"Sun or rain expected\ntoday, dark tonight"
|
|
|
|
);
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
|
|
|
Where the template is:
|
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
```smarty
|
|
|
|
{$articleTitle|nl2br}
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
|
|
|
Will output:
|
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
```
|
|
|
|
Sun or rain expected<br />today, dark tonight
|
|
|
|
```
|
2021-12-03 11:59:22 +01:00
|
|
|
|
2023-02-06 14:42:31 +01:00
|
|
|
See also [`word_wrap`](language-modifier-wordwrap.md),
|
|
|
|
[`count_paragraphs`](language-modifier-count-paragraphs.md) and
|
|
|
|
[`count_sentences`](language-modifier-count-sentences.md).
|