Joe Johnston wrote:
>>Then why don't you use perl? Calculate the answer in perl before you
>>run the template, or make a plugin (or just pass a ref to a subroutine)
>>that does what you want. TT is not meant to replace perl.
>
>
> Yes, that had occurred to me. However, this doesn't seem
> to merit a whole module.
The code required for this is quite short.
> Also, I want to get Perl out of
> the TT pages (otherwise I could have just used HTML::Mason ;-)
I never suggested putting perl code in your pages.
If you define a sub somewhere, you can pass it in as part of the stash:
sub count_matches {
my ($pattern, $string) = @_;
my @matches = ($str =~ /($pattern)/g);
return scalar @matches;
}
$template_data{'count_matches'} = \&count_matches;
Then in your template:
[% IF count_matches('foo', str) %]
You could write a plugin or an object, but you don't need to for
something this simple.
- Perrin
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates