in reply to Dynamic variable naming in Template Toolkit

Are you positive you need symbolic references? I'm pretty sure there is no support for them in TT. How is TT being invoked? From perl you pass it a vars hashref, when constructing this you can do the symbolic dereference there. Or if thats not an option why not try and pre-populate a hash instead of using symbolic references? Theres no real easy way to do this that I'm aware of.

  • Comment on Re: Dynamic variable naming in Template Toolkit

Replies are listed 'Best First'.
Re^2: Dynamic variable naming in Template Toolkit
by agianni (Hermit) on May 30, 2007 at 20:25 UTC
    How is TT being invoked?

    I could override the method that invokes the template for me (I'm using CGI::Prototype) but I'd rather not.

    why not try and pre-populate a hash instead of using symbolic references?

    That's actually what I'm doing... to start at least. There is already a large data structure being passed into the template. I'm adding an extra key to the data structure with all of the additional variables I need as keys. Then in the template, I want to turn those into simple scalar variables. Something like this:

    $ds->{for_template}->{this_key} = 'foo'; $ds->{for_template}->{that_key} = 'bar';

    Where $ds is the data structure that is already being passed into the template. Then in the template (in perl for now):

    for my $var ( keys %{ $ds->{for_template} } ){ ${eval $var} = $ds->{for_template}->{$var}; }

    Basically, I want to flatten the hash into individual variables that the template is expecting to be defined.

    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'