----- Original Message -----From: Bob DissSent: Wednesday, October 06, 2004 10:47 PMSubject: [htmltmpl] FORMAT= enhancement to <TMPL_VAR> constructGreetings! 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 valueFORMAT=uc -- uppercase the valueFORMAT=ucfirst -- ucfirst each word in the valueFORMAT=lcucfirst -- first lowercase the value, then ucfirst each wordFORMAT=reverse -- reverse the valueFORMAT=length -- output the length of the valueFORMAT=#c -- output the first # characters of the valueFORMAT=#w -- output the first # words of the valueFORMAT=#l -- output the first # lines of the valueFORMAT=xxxxx -- call the custom formatter 'xxxxx' which was declared in the 'formatters' hash when the template object was new'edNote 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