Re: [SMARTY] prefiltering variables
| From: | Andrei Zmievski | Date: | Mon, 17 Jun 2002 13:33:21 +0000 |
| Subject: | Re: [SMARTY] prefiltering variables | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4900@lists.php.net to get a copy of this message | ||
You basically want "default" modifiers, that is, modifiers that are
applied to variables whenever they are used in expressions. This point
is on the TODO list, by the way.
On Fri, 14 Jun 2002, travis@dawnstar.org wrote:
> 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:
>
> <script>alert('This is an evil alert');</script>
>
> 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 >'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
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
-Andrei http://www.gravitonic.com/
"What's a polar bear?"
"A rectangular bear after a coordinate transform."
-- Bill White (bwhite@oucsace.cs.ohiou.edu)