This is practically a copy/paste from the docs, so if the docs don't help you then this probably won't either, but here you go:
* In lib/MyApp/TT/Plugin/BBCodeFilter.pm:
package MyApp::TT::Plugin::BBCodeFilter;
use base qw(Template::Plugin::Filter);
use Parse::BBCode;
my $bbc;
sub init {
my $self = shift;
my $name = $self->{_CONFIG}->{name} || 'bbcode';
$self->install_filter($name);
$bbc = Parse::BBCode->new;
return $self;
}
sub filter {
my ($self, $text) = @_;
$text = $bbc->render($text);
return $text;
}
1;
* In the main application code:
my %tpl_settings = (
...
PLUGIN_BASE => 'MyApp::TT::Plugin',
...
);
my $tt = Template->new(%tpl_settings);
* In a random template file:
[% USE BBCodeFilter -%]
<p>[% (comments || '(No Comments)') | bbcode %]</p>
Simple as that. So what's actually causing you problems? |