Andy Wardley wrote:
> Yep, ditto.  It's also worth single quoting and escaping the hash keys,
> in case they contain any non-word characters.  

Sorry, the example I gave didn't match what I wrote there:

The generator template I was supposed to paste into generates
a hash array, which is why you would need to quote/escape the 
hash keys.

I'll try again:

 [% MACRO escape(text) GET text.replace("'", "\\'") -%]
 [% TAGS star -%]
 [% # this data is generated by the <mumble> process
    data = {
 [* FOREACH kv IN data -*]
        '[* escape(kv.key) *]' = '[* escape(kv.value) *]'
 [* END -*]
    }
 %]

If you're creating regular template variables, then they're not hash
keys and don't need to be quoted or escaped (although it doesn't hurt
if you do).  However, the names would need to contain only word 
characters.

A


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to