Re: Smarty functions help

From: Date: Tue, 22 Oct 2002 15:44:16 +0000
Subject: Re: Smarty functions help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120931@lists.php.net to get a copy of this message
> Im using smarty template engine .. Id like to know if theres a way to > place php functions, specifically nl2br(), into smarty templates .. Not > in php script that calls smarty class. Take a look at the modules/ folder in Smarty. You can create your own modifier to use in your templates. You'd want to make a file called modifier.nl2br.php and have it's contents something like this: <?php /* * Smarty plugin * ------------------------------------------------------------- * Type: modifier * Name: nl2br * Purpose: add <br /> to all newlines in string * ------------------------------------------------------------- */ function smarty_modifier_nl2br($string) { return nl2br($string); } ?> and then you'd display your value like {$value|nl2br} in the templates. You could just use the nl2br() function in your assign(), too: $smarty->assign('text',nl2br($text)); ---John Holmes...

« previous php.general (#120931) next »