On Oct 9, 2008, at 1:13 PM, Josh Rosenbaum wrote:

> 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.

Thanks Josh,

I had thought of doing that but somehow got this misguided idea in my  
head that there must be an easier way.
Shouldn't have kept busting my head against the wall looking for an  
'easier' way.


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

Reply via email to