On Wed, 10 Sep 2003, David Castillo Horcas wrote:

> Hellow, 

> I want to built a recurrent function with the template toolkit
> because i have a hash with a recurrent list (like a tree) and i
> want to display this list in a select menu in the HTML page. 
> 
> I�ts possible built functions with template toolkit?

Si.  Es posible.  :)

You can use the MACRO directive to build functions within templates.
Here's a sample in a self-contained script (the example is useless
but it proves you can do recursive functions in templates):



#!/usr/bin/perl

use strict;
use Template;

my $tt2 = new Template();
$tt2->process(\*DATA) || die $!;

__DATA__
[%- # be sure the MACRO definition comes _before_ the first call to it %]
[%- MACRO recursive_function(list, item, level) BLOCK %]
[%-    spacer = ' ' %]
[%-    spacer.repeat(level); list.$item %]
[%     nextitem = item + 1 %]
[%-    nextlevel = level + 1 %]
[%-    IF (nextitem < list.size) %]
[%-        recursive_function(list, nextitem, nextlevel) %]
[%-    END %]
[%- END -%]

[%- list = ['A', 'B', 'C'] %]
[%- recursive_function(list, 0, 1) -%]




> Tank you! and sorry for my English, i know it only a bit.

Es mejor que mi espanol...

Take care,

Dave

/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash                              Power to the People!
Frolicking in Fields of Garlic               Right On-Line!
[EMAIL PROTECTED]                                  Dig it all.


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to