Re: [Templates] Question about overloading Stash->get()

[prev] [thread] [next] [Date index for 2005/01/18]

From: Josh Rosenbaum
Subject: Re: [Templates] Question about overloading Stash->get()
Date: 08:56 on 18 Jan 2005
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

[Templates] Question about overloading Stash->get()
Andrew Williams 21:18 on 17 Jan 2005

Re: [Templates] Question about overloading Stash->get()
merlyn (Randal L. Schwartz) 08:40 on 18 Jan 2005

Re: [Templates] Question about overloading Stash->get()
Josh Rosenbaum 08:56 on 18 Jan 2005

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52