Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: locale for date in Template Toolkit

by sundialsvc4 (Abbot)
on Feb 19, 2014 at 16:03 UTC ( #1075473=note: print w/ replies, xml ) Need Help??


in reply to locale for date in Template Toolkit

Also, and for whatever this may be worth, “this sort of thing” is not what I like to see in the source-code of a template.   Instead, I prefer to see it either as a Perl-supplied input variable (which could of course be a closure ...), or as a custom function (defined in the Perl) that performs the task.   (Which is, in this case, “display this date according to ‘the client language’.”   IMHO, the template should neither contain the exact format-string, nor the logic for deducing what ‘the client language’ is.   Think ahead ... The Marketing Department™ will want to change this!   Endlessly.   Of course, after you have cut ’n pasted it a zillion-and-one times.   You want to be able to change it in one place, then walk away with a smug grin on your face as the Dumbfounded Marketroids praise you as a genius.

Situations such as this one are where I would advocate that you should strive to “write what you mean,” then provide an implementation for that “meaning” in one, and only one place.   The code that you show in the OP is not “meaning,” but concrete implementation, ripe to be repeated.   This templating system makes all of this very easy to do.


Comment on Re: locale for date in Template Toolkit
Re^2: locale for date in Template Toolkit
by Anonymous Monk on Feb 19, 2014 at 18:29 UTC

    Also, and for whatever this may be worth, “this sort of thing” is not what I like to see in the source-code of a template...

    Nobody asked you

    Its perfectly reasonable to use a template as a config file to configure other templates without programming any perl

      Kind Monk, why did we build this Monastery, but to solicit the opinions and perhaps the counsel of our Peers? . . .   Peace.

Re^2: locale for date in Template Toolkit
by RenardBleu (Novice) on Feb 20, 2014 at 12:56 UTC
    It was only a template toolkit test (the former coder used to code a lot of things in tt2 since it was annoying our boss...), the actual code is indeed done in Perl with Date::Calc and given to Template Toolkit.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1075473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-22 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls