Re: [SMARTY] nl2br in a template?
| From: | gawan | Date: | Fri, 21 Feb 2003 23:21:50 +0000 |
| Subject: | Re: [SMARTY] nl2br in a template? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8111@lists.php.net to get a copy of this message | ||
"Paul Lockaby" <lockaby@vt.edu> wrote in message
news:3E56B199.1080001@vt.edu...
> gawan wrote:
> > Hi
> >
> > I have text fields from a database to display through smarty template.
> > Is there a convenient way to use something similar to php nl2br()
> > to show new lines as <br> tags when in a template?
> >
> > gawan
> >
>
> Yes! Using a plugin for this is ideal. Here is an example:
>
> function smarty_modifier_nl2br($message) {
> return nl2br($body);
> }
>
> Put that in a file by itself, named modifier.nl2br.php and then in your
> template file, simply call it like this:
>
> { $var|nl2br }
>
> And poof(!) $var will have all newlines replaced with <BR>s. You can
> also check out this page right here:
>
> http://smarty.incutio.com/?page=SmartyPlugins
>
> For more ideas on plugins you can use to modify your text. I especially
> like the bbcode2html plugin and use a modified version of it on my own
site.
>
> Hope that helps!
> ~Paul
Thanks Paul, for a really quick answer!
And I thought plugins are something difficult.
This examble helps to understand them in general, thanks.
gawan