On Thu, 19 Aug 2004, Buddy Burden wrote:

> Okay, the canonical MACRO example goes something like:
>
>       [% MACRO commify(n) GET n.chunk(-3).join(',') %]

It ain't pretty, but how about:

        [% MACRO commify(n) GET n.match('^([^.]+)').0.chunk(-3).join(',') _ 
n.match('(\..+)$').0 %]

or for European numbers:

        [% MACRO dotify(n) GET n.match('^([^,]+)').0.chunk(-3).join('.') _ 
n.match('(\,.+)$').0 %]

> Simple enough.  But what if you have decimal places on the end?  I mean,
> I know I can do this the hard way, but I keep feeling like I'm missing
> something.  Is there some easy way, or maybe existing
> plugin/filter/predefined macro somewhere?  I'm sure it's a problem
> others have faced before me.

OK, maybe my suggestion's the hard way.  But it was fun to write!

Hope that helps,

Dave

P.S. For the record, this was my first try:

        [% MACRO commify(n) BLOCK; GET n.split('\.').0.chunk(-3).join(','); GET '.' _ 
n.split('\.').1 IF n.match('\.').0; END %]

I didn't benchmark to see which was faster.

/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash                              Power to the People!
Frolicking in Fields of Garlic               Right On-Line!
[EMAIL PROTECTED]                                  Dig it all.

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to