Re: [Templates] Question about overloading Stash->get()
[prev]
[thread]
[next]
[Date index for 2005/01/18]
Randal L. Schwartz wrote:
>>>>>>"Andrew" == Andrew Williams <amw1@xxxxx.xxx> writes:
>
>
> Andrew> I want to automatically html escape unsafe chars in any value
> Andrew> that is displayed to the user. i.e. [% foo %] should have <
> Andrew> and >'s escaped.
>
> And what doesn't
>
> [% foo | html %]
>
> do for you that you need?
>
I imagine it probably gets tedious to type '| html' (or html_entity)
everytime. Not to mention if he has already wrote tons of pages, it can
get tedious to go over them and change everything.
Andrew, I don't have a good solution for you. If you don't have a lot
of pages and you're just looking for shorthand, you could use a 'hack'
like this:
$Template::Stash::SCALAR_OPS->{ h } =
sub {
my ($scalar) = @_;
return HTML::Entities::encode($scalar);
};
Then just do: [% foo.h %]. You might have to do [% foo.h() %] as I
didn't test that. Hopefully someone can help you with your original
question.
-- Josh
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates