On Mon, Sep 05, 2005 at 02:42:21PM +0100, Andy Wardley wrote:
> 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.
Thanks.
I decided to make a plugin instead. That allowed me to move all the
functionality of the program that generates the data-structure into
the plugin as well. Which also means that I won't need the temporary
config-file with the variables anymore.
--
Trond Michelsen
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates