http://www.template-toolkit.org/docs/leon/Manual/Config.html#Plugins_and_Filters
Look at defining your own FILTER.
You should be able to add in to your perl code a sub like this super-naive version that you really shouldn't copy and use.
sub hilite_filter {
my $txt = shift;
my $match = shift or return;
my $image = shift or '<em>!!</em>';
$txt =~ s/($match)/$image$1/g
return $txt;
}And when you create the Template object you need to add the filter with a configuration directive:
$template = Template->new({
FILTERS => {
'hilite' => [ \&hilite_filter, 1 ],
},
});You'll want to be a bit fancier than that. There is also a way you can add the Filter dynamically if you can't or won't do it during the Template object creation.
--mark
Jesse Sheidlower wrote:
I assume there must be a usual way to do this, but it wasn't clear from the parts of the Manual I've been looking at.
I have something I'm converting to TT from a CGI.pm-based
system. Part of it involves taking text that has been searched by a search engine, and highlighting the search
word that has been found. I had been doing it more or less like this:
--- my $image = "<img src=\"\/images/ball.red.small.gif\">"; my $search_word = "foo"; # populated somehow my $text = "Here I want foo highlighted."; # also populated somehow
$text =~ s/($search_word)/$image$1/ig; # now $text is: # Here I want <img src="/images/ball.red.small.gif">foo highlighted. ---
What's the more TT-ly way of doing this?
Thank you.
Jesse Sheidlower
_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates
_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates
