Re: [Templates] DateTime not working with TT
[prev]
[thread]
[next]
[Date index for 2004/10/15]
Dave Boodman <dave.lists@xxxxxxx.xxx> writes:
> 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) %]
Just nitpicking: You might want to use the CALL keyword here:
[% CALL date.add(days => 32) %]
This avoids that the result of the date.add method is being printed in
your HTML output.
> 32 days from today is [% date.year %]/[% date.month %]/[% date.day %]
> --------------------
> [...]
> Has anyone gotten this working?
Your program is running without problems here:
------------------------------------------------------------------
Today is 2004/10/15.
2004-11-16T00:00:00
32 days from today is 2004/11/16
------------------------------------------------------------------
> Vitals:
>
> FreeBSD: 4.10
> Perl: v5.6.1
> TT: Template-Toolkit-2.13
> Template-Plugin-DateTime-0.01
> DateTime-0.21
This is cygwin Perl 5.8.3, but I can hardly believe it's a Perl issue.
Or maybe it is? I'm sorry, but the only 5.6.1 installation here is a
rather outdated NTAR system which doesn't have DateTime installed at
all...
The only other difference I can see is that I'm having DateTime-0.22.
The Changes file doesn't indicate anything relevant to your problem in
this release. However, you might want to give it a try - the Changes
also indicate that stringification overloading has been brought (back)
to DateTime in version 0.21, and maybe some bug has been fixed since
then.
--
Cheers,
haj
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|