[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: 04:01 on 14 Oct 2004
I'm having a problem getting access to DateTime object functions inside a template. 

The code looks like this:

test.pl:

--------------------

use Template;
use Template::Plugin::DateTime;
my $template = Template->new({
    INCLUDE_PATH => "/tmp",
    PLUGIN_BASE => 'Plugin',
    COMPILE_DIR => '/tmp',
    DEFAULT => '404.html',
});

my $output;

$template->process('test.html', $vars, \$output) or die $template->error();
print $output;

--------------------

test.html:

[% USE date = DateTime(today = 1) %]
Today is [% date.year %]/[% date.month %]/[% date.day %].
[% date.add(days => 32) %]
32 days from today is [% date.year %]/[% date.month %]/[% date.day %]

--------------------

The result is:

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.

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 "print $datetime_obj"

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. 

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.

Has anyone gotten this working?

Vitals:

FreeBSD: 4.10
Perl: v5.6.1
TT: Template-Toolkit-2.13
Template-Plugin-DateTime-0.01
DateTime-0.21

Thanks! 


_______________________________________________
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