[Templates] Problems with reserved words as hash keys
[prev]
[thread]
[next]
[Date index for 2004/12/15]
Template Toolkit chokes when it encounters reserved words (in uppercase)
used as hash keys or method names. For example:
[% person =3D {=20
FIRST =3D 'Jason'=20
LAST =3D 'Gottshall'
} # generates: file error - parse error - unexpected token
(LAST) %] =20
You are on step [% action.STEP %] of a 3-step process.
[%# generates: file error - parse error - unexpected token
(STEP) %]
I know of a few work-arounds for these issues: quote my hashkeys, use
the hash.item() vmethod, or do something like [% action.${'STEP'} %]. Of
course I could also use lowercase key names. Or avoid naming my keys the
same as reserved words to begin with.=20
The main issue is that I'm dealing with legacy code. I've got existing
data-retrieval modules (used as plugins under TT) that are already
returning hashes/objects with uppercase keys/method names (mostly due in
turn to Oracle's habit of returning data that way). And to compound the
issue, I've got non-programmer template designers who don't yet
recognize a reserved word when they see it, and have trouble remembering
the work-arounds even when they do. Anyway, I'd appreciate any thoughts
you all might have on dealing with this issue. It could be that I'll
just have to muddle through until TT3 (this is fixed in TT3, right
Andy?)
Incidentally, can anyone tell me why STEP and TO are reserved words? Is
this a holdover from TT1? I can't find any reference to them in the
docs...
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
[Templates] Problems with reserved words as hash keys
Jason Gottshall 23:31 on 15 Dec 2004
|