[Templates] DateTime not working with TT

[prev] [thread] [next] [Date index for 2004/10/14]

From: Dave Boodman
Subject: [Templates] DateTime not working with TT
Date: 03:50 on 14 Oct 2004
<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-&gt;new({<br>
&nbsp;&nbsp;&nbsp; INCLUDE_PATH =&gt;
</font><font face="Courier New, Courier" size=2 color="#800000"><i>&quot;/tmp&quot;</i></font><font face="Courier New, Courier" size=2>,<br>
&nbsp;&nbsp;&nbsp; PLUGIN_BASE =&gt;
</font><font face="Courier New, Courier" size=2 color="#800000"><i>'Plugin'</i></font><font face="Courier New, Courier" size=2>,<br>
&nbsp;&nbsp;&nbsp; COMPILE_DIR =&gt;
</font><font face="Courier New, Courier" size=2 color="#800000"><i>'/tmp'</i></font><font face="Courier New, Courier" size=2>,<br>
&nbsp;&nbsp;&nbsp; DEFAULT =&gt;
</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-&gt;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-&gt;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 =&gt; 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
&quot;2004-10-14T00:00:00&quot;, the same thing I get if I create a new
DateTime object and do &quot;<font face="Courier New, Courier">print
$datetime_obj</font>&quot;<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).&nbsp; 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

[Templates] DateTime not working with TT
Dave Boodman 04:01 on 14 Oct 2004

Re: [Templates] DateTime not working with TT
Harald Joerg 07:59 on 15 Oct 2004

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52