On Tue, 22 Jan 2002, Benjamin wrote:
> The datastructure so far is no proplem, but for a arbitrary tree you
> need something like recursion, at least that's the way I do it. And
> HTML::Template doesn't provide anything like that. The way to do a tree
> with HTML::Template would be using <TMPL_LOOP>s, but I would have to
> hardcode the deepest recursion level into the template, what isn't quite
> the thing I want to do.
If you're dead set on doing it with nested tmpl_loops then you'll have to
generate your template programattically, possible using a separate
template to generate your final template. I don't think there's an easy
solution here but it can be made to work.
However, most of the time you can use a different solution - flatten the
data. For example, let's say I wanted to display a tree like this:
- foo
- bar
- baz
- bif
Instead of using nested loops I would use a single loop with an indent
variable:
<tmpl_loop tree>
<indent size=<tmpl_var indent>>- <tmpl_var data><br>
</tmpl_loop>
(Um, pretend that HTML would indent the content by "indent" pixels.) And
pass the data structure:
$template->param(tree => [ { indent => 10, data => 'foo' },
{ indent => 20, data => 'bar' },
{ indent => 20, data => 'baz' },
{ indent => 30, data => 'bif' }, ]);
Now, you'll probably need to use a recursive subroutine to generate the
flattened loop, but that's no big deal. At the end of the day you'll have
a simple template and some fairly complex code - perfect!
-sam
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]