access variable member "*" in template

75 views Asked by At

i have a variable

var1 = {
  '*'                   = >        {
    'counter'           = >        {
      'default'     = > '0',
      'description' = > 'test'
     }
   }
 }

in perl template toolkit. How can i access the content of '*' in the template.

[% var1.*.counter %]

does not work because of the symbol is no valid name.

1

There are 1 answers

8
Borodin On BEST ANSWER

You can define a variable to be equal to * within the template, and use that instead.

[% star = '*' %]
[% var1.$star.counter.description %]

But I wonder why you have to have an asterisk as a key in the first place? It would be far better to provide a sensible key at the Perl level, perhaps by writing

$vars->{var1}{star} = $vars->{var1}{'*'}

before you call the Template Toolkit.