[Templates] DateTime not working with TT
[prev]
[thread]
[next]
[Date index for 2004/10/14]
<html>
<body>
I'm having a problem getting access to DateTime object functions inside a
template. <br><br>
The code looks like this:<br><br>
test.pl:<br><br>
<font face="Courier New, Courier" size=2>--------------------<br><br>
<b>use</b> Template;<br>
<b>use</b> Template::Plugin::DateTime;<br>
<b>my</b> $template = Template->new({<br>
INCLUDE_PATH =>
</font><font face="Courier New, Courier" size=2 color="#800000"><i>"/tmp"</i></font><font face="Courier New, Courier" size=2>,<br>
PLUGIN_BASE =>
</font><font face="Courier New, Courier" size=2 color="#800000"><i>'Plugin'</i></font><font face="Courier New, Courier" size=2>,<br>
COMPILE_DIR =>
</font><font face="Courier New, Courier" size=2 color="#800000"><i>'/tmp'</i></font><font face="Courier New, Courier" size=2>,<br>
DEFAULT =>
</font><font face="Courier New, Courier" size=2 color="#800000"><i>'404.html'</i></font><font face="Courier New, Courier" size=2>,<br>
});<br><br>
<b>my</b> $output;<br><br>
$template->process(</font><font face="Courier New, Courier" size=2 color="#800000"><i>'test.html'</i></font><font face="Courier New, Courier" size=2>,
$vars, \$output) <b>or</b> <b>die</b> $template->error();<br>
<b>print</b> $output;<br><br>
--------------------<br><br>
test.html:<br><br>
[% USE date = DateTime(today = 1) %]<br>
Today is [% date.year %]/[% date.month %]/[% date.day %].<br>
[% date.add(days => 32) %]<br>
32 days from today is [% date.year %]/[% date.month %]/[% date.day
%]<br><br>
--------------------<br><br>
</font>The result is:<br><br>
<font face="Courier New, Courier">undef error - Cannot compare a datetime
to a regular scalar at
/usr/local/lib/perl5/site_perl/5.6.1/mach/DateTime.pm line
1255.<br><br>
</font>Basically, it looks like it's passing the time scalar instead of
the object (it's doing a compare of values instead of a call to the year
method. I can confirm this by looking at the input to the
DateTime::_compare function is, which shows as
"2004-10-14T00:00:00", the same thing I get if I create a new
DateTime object and do "<font face="Courier New, Courier">print
$datetime_obj</font>"<br><br>
I've tried to get this working using the Template::Plugin::DateTime
module (used above) and by passing the DateTime obj as a var into the TT
- both attempts gave the same result. <br><br>
As I said, it appears that this is TT not knowing that I want to call
date as an obj not a hash or scalar (and the obj can be both). OT:
oddly, so can Time::Piece and that works as expected.<br><br>
Has anyone gotten this working?<br><br>
Vitals:<br><br>
FreeBSD: 4.10<br>
Perl: v5.6.1<br>
TT: Template-Toolkit-2.13<br>
Template-Plugin-DateTime-0.01<br>
DateTime-0.21<br><br>
Thanks!</body>
</html>
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|
 |
 |
[Templates] DateTime not working with TT
Dave Boodman 03:50 on 14 Oct 2004
|