Randal L. Schwartz wrote:
"Andrew" == Andrew Williams <[EMAIL PROTECTED]> 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
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to