----- Original Message -----
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