Re: [SMARTY] htmlentities to all assigned variables
| From: | M Mohr | Date: | Wed, 15 Jan 2003 18:56:31 +0000 |
| Subject: | Re: [SMARTY] htmlentities to all assigned variables | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7200@lists.php.net to get a copy of this message | ||
Hello,
On Wed, Jan 15, 2003 at 07:59:50PM +0200, Alex wrote:
> Hi!
> I have a following problem:
> I need to apply htmlentities() function to all assigned variables.
> I know I can use {$AnyVar|escape} but for this I need to remake a huge
> template's files. I tried to find any solution with plugins, but I
> couldn't. Now I have several solution but none of them not looks good.
> For example I can make Smarty child class and overload assign()
> function.
> Anybody have any ideas?
all the assigned template-vars are in an associative array in
$smarty->_tpl_vars
if you do not assign and modify them inside you template, you can
modify them all assigned ones before your call to display() or
fetch():
(untested code)
foreach ($smarty->_tpl_vars as $name=>$value) {
if (!is_array($value) && !is_object($value))
$smarty->_tpl_vars[$name] = htmlentities($value);
}
to handle arrays and objects you need to traverse the variables
recursively. i have such a function somewhere and can it look up
for you, if you need that and don't want to try yourself.
have fun
messju
> Thanks,
> Alex.