On Thu, 14 Jun 2001, Adam Theo wrote:

> is there anyway to get template::toolkit to parse the hash recursively?

See the section on views.
http://www.template-toolkit.org/docs/default/Manual/Views.html

You want to define a view that if it's called with a hash it uses itself
to print out the hash values (which in turn may recursively call the
child hashes to be rendered, and so on..)

[% # the view %]
[% VIEW v %]

 [% BLOCK hash %]
 <ul>
  [% FOREACH key = item.keys.sort %]
   <li>[% key %] => [% view.print(item.$key) %]</li>
  [% END %]
 </ul>
 [% END %]

 [% BLOCK text %][% item %][% END %]

[% END %]

[% # a data structure %]
[% bob = { "foo" => { "bar"    => "baz",
                      "fred"   => "wilma",
                      "barney" => "betty",
                    },
           "fish" => { "tree" => { "car" => "cod",
                                   "abc" => "def",
                                 },
                       "opal" => "fruit",
                       "mars" => "bar",
                      },
           } %]

<html>
<body>
[% v.print(bob) %]
</body>
</html>

This gives, from lynx --dump

     * fish =>
          + mars => bar
          + opal => fruit
          + tree =>
               o abc => def
               o car => cod
     * foo =>
          + bar => baz
          + barney => betty
          + fred => wilma


Later.

Mark.

-- 
s''  Mark Fowler                Technology Developer         Profero Ltd
     http://www.profero.com/      [EMAIL PROTECTED]         020 7700 9960
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/  +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}



Reply via email to