Template Toolkit ... is there a bug in the ANYCASE setting??

V

valued customer

The code snippet below produces an error "unexpected token (LAST)".
Changing the ANYCASE property to false (zero) removes the error and
the code behaves as expected.

The question is, is this a bug? According to the TT2 documentation,
the ANYCASE property has a side effect of precluding reserved words as
variable names, does this also preclude using the 'loop.last'
directive? Any TT2 experts out there? Tips? Suggestions? Thanks in
advance.

### INIT library
use strict;
use warnings;
use Template;

### INIT variables
my $tt =
Template->new( { ANYCASE => 1,}) || die "$Template::ERROR\n";

### INIT Source Data
my $data = { list => [ qw(one two three four five) ]};

### PROCESS TEMPLATE
my $strOut;
$tt->process(\*DATA, $data, \$strOut) || die $tt->error(), "\n";
print $strOut;

__DATA__
[%-FOREACH item = list;
"<BEGIN>\n" IF loop.first;%]
[%- item %]
[%"<END>" IF loop.last;
END;%]
 
D

Dave Cross

The code snippet below produces an error "unexpected token (LAST)".
Changing the ANYCASE property to false (zero) removes the error and
the code behaves as expected.

The question is, is this a bug? According to the TT2 documentation,
the ANYCASE property has a side effect of precluding reserved words as
variable names, does this also preclude using the 'loop.last'
directive? Any TT2 experts out there? Tips? Suggestions? Thanks in
advance.

### INIT library
use strict;
use warnings;
use Template;

### INIT variables
my $tt =
Template->new( { ANYCASE => 1,}) || die "$Template::ERROR\n";

### INIT Source Data
my $data = { list => [ qw(one two three four five) ]};

### PROCESS TEMPLATE
my $strOut;
$tt->process(\*DATA, $data, \$strOut) || die $tt->error(), "\n";
print $strOut;

__DATA__
[%-FOREACH item = list;
"<BEGIN>\n" IF loop.first;%]
[%- item %]
[%"<END>" IF loop.last;
END;%]

LAST is also a template directive (for exiting loops) so it seems that the
parser is getting slightly confused in this situation. Probably worth
letting the TT mailing list know (as that's where the real TT experts hang
out).

Dave...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top