in reply to How do I cope with nested TMPL_VAR in HTML::Template::Pro?

Is there a way to cope with this elegantly?

Preprocess the data you send to the template system to form that the template system can understand.

  • Comment on Re: How do I cope with nested TMPL_VAR in HTML::Template::Pro?

Replies are listed 'Best First'.
Re^2: How do I cope with nested TMPL_VAR in HTML::Template::Pro?
by PerlOnTheWay (Monk) on Aug 03, 2011 at 14:54 UTC

    How?

    There's no way to change a variable to a constant,right?

      If you template snippet would work, the data input for it would look like
      $tmpl->param(loopname => [ { anothervariable => 'foo', foo => 'actual value', }, ... ])

      You need to change that to

      $tmpl->param(loopname => [ { fixed_key => 'actual value', }, ... ])

      For example by creating a fixed coyp of each hashref like this:

      my $new = { fixed_key => $old->{$old->{anothervariable}} };

        Consider the case you use DBI to fetch the result of show tables,

        whose keys are in the format Tables_in_db_name, there's no way to reduce it into a fixed key,

        as it changes according to the database name .

        Is there a better option than copy the whole hash into another one with fixed keys(as obviously this is causing duplicate data)?