Sean Allen wrote:
[SNIP]
> if i do
> 
> 'number_format' => Number::Format->new( ... )
> 
> then the filter isnt defined.
> 
> if i do
> 
> 'number_format' => Template::Plugin::Number::Format->new( ... )
> 
> I get:
> 
> Can't call method "define_filter" without a package or object reference 
> at /usr/local/share/perl/5.8.8/Template/Plugin/Number/Format.pm line 74.
> 
> so what am i doing wrong?

Defining a variable won't give you the filter. Also, pointing to the plugin 
won't give you the filter either.

Try using the FILTERS config option and creating a dynamic filter manually. 
You'll need to do this for each filter you want to add.

Here is a possible example. It may need work, but should get you started:
========================================
# Define this globally so we don't have to recreate it over and over.
# Probably only need to do this if it's used every time.
my $num_formatter = new Number::Format( thousands_sep => ',',  decimal_point => 
'.', int_curr_symbol => '', decimal_digits => '2', decimal_fill => 't' );

my $template_config = {
  FILTERS => {
    'format_number' => [sub {
      my ($context, @args) = @_;
      return sub {
        my $value = shift;
        return $num_formatter->format_number($value, @args);
      };
    }, 1]
  }
};

my $template = Template->new($template_config);

========================================

Hope that helps ya. Basically you can get rid of the plugin and just create the 
filters yourself.

-- Josh

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to