Le 24 d�c. 03, � 00:56, Jason Lewis a �crit :

Hi,

How would I escape certain characters from the template output so they don't interfere with LaTeX?

I have tt code that looks like this:

.
.
.
[% END #IF %]
  [%-item.title-%]&& [%-item.accountno-%]\hline
[%- IF item.CatagoryTitle != loop.next.CatagoryTitle %]
.
.
.

item.title may contain ' or other characters which LaTeX is sensitive to in it. I'd like to pass item.title (and possibly other fields) through a regex that can escape all latex characters. any ideas?

I'm sure i saw some doco on the TT web site about using regexps, but I can't seem to find it now.

Jason

I had to do a similar thing to escape single quotes in strings that were being
used in Javascript ( var foo = '[% stuff %]'). I decided that wether [% stuff %]
was going to be used in Javascript and therefore need to be escaped was a template
decision so I wrote a filter:
... FILTERS => { javascript_escape => \&javascript_escape }
...
sub javascript_escape {
my $text = shift;
$text =~ s/'/\\'/g;
return $text;
}


So now in the template I can do this:

var foo = [% stuff | javascript_escape %]

This lets the template author decide when to javascript_escape(), not
my Perl code.

HTH,
--
Eric Cholet


_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to