Re: [htmltmpl] FORMAT= enhancement to <TMPL_VAR> construct
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-10-07 02:59:22
|
yes - but the question was whether this type of functionality was = suitable to be added as a native capability. Mathew > All those and more can be done using HTML::Template::Expr. >=20 >=20 > > 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: htm...@li... > > Sent: Wednesday, October 06, 2004 10:47 PM > > Subject: [htmltmpl] FORMAT=3D 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=3Dsome-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=3Dlc -- lowercase the value > > FORMAT=3Duc -- uppercase the value > > FORMAT=3Ducfirst -- ucfirst each word in the value > > FORMAT=3Dlcucfirst -- first lowercase the value, then ucfirst = each word > > FORMAT=3Dreverse -- reverse the value > > FORMAT=3Dlength -- output the length of the value > > FORMAT=3D#c -- output the first # characters of the value > > FORMAT=3D#w -- output the first # words of the value > > FORMAT=3D#l -- output the first # lines of the value > > FORMAT=3Dxxxxx -- 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? > > |