prefiltering variables

From: Date: Fri, 14 Jun 2002 15:18:46 +0000
Subject: prefiltering variables
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4840@lists.php.net to get a copy of this message
Is there some kind of "variable prefilter" option to cause Smarty to filter/transform the values assigned in the template? For example, I'd like to render some variable called $description, so in my PHP I do this: $smarty->assign( "description", $description ); Then, in the template I do this: {$description} But suppose $description contains the string: <script>alert('This is an evil alert');</script> I'd like Smarty to know that it should output: &lt;script&gt;alert('This is an evil alert');&lt;/script&gt; I know I can filter such user-entered data at the input stage, but I don't like this at all for two reasons: (1) It's a lot of extra code, and (2) there's no reason to assume anything about how the information is to be extracted from the database. Maybe I'll be pulling it into an Excel spreadsheet, in which case I don't want to see all those &gt;'s. I also know I can filter this when I assign the variable from PHP, but that's even worse, because I may have to loop through arrays, and arrays of arrays, and so on. Very messy and bug prone. I can't use a prefilter, because the data isn't in the template yet. I can't use a postfilter because at that point there is no way to differentiate between the template and the data. So I'd really like Smarty to do it. It seems the cleanest approach. Is there a way to do this already, or can this be added? cheers, Travis

« previous php.smarty.general (#4840) next »