Search code examples
perltemplate-toolkit

Perl Logic in Template Toolkit


I have a currency value that I would like to format using Locale::Currency::Format however I have no idea how to format it.

Here is my output in Template Toolkit

[% amount %]

I would like this to be outputted using the following method:

currency_format('USD', amount, FMT_SYMBOL)

New to template toolkit so any help is appreciated.


Solution

  • I like Dave Cross' answer, and I agree with both he and codnodder about EVAL_PERL, which I've yet to find necessary as a solution in 7 or 8 years of almost daily TT use.

    Personally, I would use:

    [%- USE fmt = Class('Locale::Currency::Format'); -%]
    
    <td>[% fmt.currency_format(var1, var2, var3) %]</td>
    

    But if I was using this all the time, I'd be tempted to write a TT plugin wrapper around it.