I'd generally agree (mostly) -> the formatting of data is up to the GUI designer, eg if I want the number 1000000 to contain comma's, I shouldn't need to get the Perl programmer to generate the a stringified value caontaining them.
 
Although, there would need to be alimit on this functionality, as you might end up making a scripting language just to implement this extra functionality, in a way which is extensible.  In which case, you might as well just write a Perl module to do the formatting for you.
 
regards,
Mathew
 
----- Original Message -----
From: Bob Diss
To: html-template-users@lists.sourceforge.net
Sent: Wednesday, October 06, 2004 10:47 PM
Subject: [htmltmpl] FORMAT= enhancement to <TMPL_VAR> construct

Greetings!  In using HTML::Template I found somewhat limited by the lack of formatting ability in the template language itself.  While I recognize the need for a separation between coding and layout, I often found myself making duplicate copies of a value in different formats so that the layout people would have the version they need.  For example: sometimes they would want the value in all uppercase (for a section heading), and then again they want it in all lowercase, or sometimes they want just the first few words (to layout an article teaser).
 
To do this I implemented an idea I had seen done by a PHP translation of HTML::Template found at http://vlib.activefish.com/docs/vlibTemplate.html.  The "FORMAT=some-value" attribute to the <TMPL_VAR> construct allows the designer to alter the format of the variable.  I implemented several built-in formatters, including:
 
FORMAT=lc  --  lowercase the value
FORMAT=uc  --  uppercase the value
FORMAT=ucfirst  --  ucfirst each word in the value
FORMAT=lcucfirst  --  first lowercase the value, then ucfirst each word
FORMAT=reverse  --  reverse the value
FORMAT=length  --  output the length of the value
FORMAT=#c  -- output the first # characters of the value
FORMAT=#w  --  output the first # words of the value
FORMAT=#l  --  output the first # lines of the value
FORMAT=xxxxx  --  call the custom formatter 'xxxxx' which was declared in the 'formatters' hash when the template object was new'ed
 
Note that FORMAT does not replace ESCAPE.  Instead, they happen in sequence.  First, the value is formatted, then it is escaped.
 
Comments?  Thoughts?  Suggestions?
 
- Bob Diss
 

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com