Re: [SMARTY] nl2br in a template?

From: Date: Wed, 26 Feb 2003 21:44:40 +0000
Subject: Re: [SMARTY] nl2br in a template?
References: 1 2 3  Groups: php.smarty.dev php.smarty.general 
Request: Send a blank email to php-smarty-dev+get-846@lists.php.net to get a copy of this message
This can be added, sounds useful enough. A few questions: 1) Is there a better name, or keep nl2br for consistancy of PHP developers familiarity? nl2br is nice and short though... 2) Should it always return XHTML compliant code <br />, regardless of PHP version? the PHP command nl2br() pre-PHP 4.0.5 doesn't output XHTML break tags. I think it would be good to always be XHTML compliant. 3) Should it cover newline formats from Mac/PC appropriately? In otherwords replace \n or \r\n with <br /> tags? 4) Should it replace newlines already preceeded by a <br> tag? Controllable option? If so, what should be default? Monte On Wed, 2003-02-26 at 10:59, Pete wrote: > Could this function go in the standard distrinution as I'm sure > everyone else uses it > > Pete > > function smarty_modifier_nl2br($message) { > return nl2br($body); > } > > > > > Paul Lockaby wrote: > > 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 > > -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.dev (#846) next »