On Thu, 27 Jul 2000, Jacob Davies wrote:
> The first is easy template-coder-controlled HTML-escaping of
> interpolated values, so I (the Perl programmer) can just throw
> unescaped form data back into the template, and the templater-coder
> can do:
> 
> <INPUT TYPE="TEXT" NAME="first_name" VALUE="<#FIRST_NAME HTMLESC>">

To do this with Template Toolkit, I map the Apache::Util escaping
functions in the data I pass when I execute the template:

$args{'DATA'}->{'html'} = \&Apache::Util::escape_html;

Then I can just say this:

[% html(first_name) %]

> The second is easy template-coder-controlled URL-escaping of
> interpolated values

Same deal, but with Apache::Util::escape_uri.

> The third is easy template-coder-controlled -- are you detecting a pattern
> here? -- conversion of template data to SELECTED or CHECKED, so they can do
> this:
> 
> <INPUT TYPE="CHECKBOX" NAME="option_1" <#OPTION_1 CHECKEDIF="on"> >

I do this with IF constructs, which is not as compact as your example but 
it works:

[% "checked" IF my_checkbox == option_1 %]

(This assumes I've put the name of the selected checkbox into
my_checkbox.)

I'm sure other systems allow something similar.

- Perrin

Reply via email to