$ cat recurse.tt2 [% BLOCK recurse %] [% META name = 'my file' -%] recursion count: [% counter %] [% counter = counter + 1 -%] [% RETURN IF counter > 3 -%] [% PROCESS recurse %] [% END %] [% PROCESS recurse counter = 1 %] [% FOREACH variable IN [ 6, 7, 9 ] %] The variable is set to [% variable %] [% END %]
$ tpage recurse.tt2 recursion count: 1 recursion count: 2 recursion count: 3 The variable is set to 6 The variable is set to 7 The variable is set to 9
#--------------------------------------------------------------------- +--- # Compiled template generated by the Template Toolkit version 2.22 #--------------------------------------------------------------------- +--- Template::Document->new( { METADATA => { 'modtime' => '1297498495', 'name' => 'my file', }, BLOCK => sub { my $context = shift || die "template sub called without co +ntext\n"; my $stash = $context->stash; my $output = ''; my $_tt_error; eval { BLOCK: { $output .= " \n \n"; #line 9 "recurse.tt2" $output .= $context->process( 'recurse', { 'counter' => 1 } + ); $output .= " \n "; #line 12 "recurse.tt2" # FOREACH do { my ( $_tt_value, $_tt_error, $_tt_oldloop ); my $_tt_list = [ 6, 7, 9 ]; unless ( UNIVERSAL::isa( $_tt_list, 'Template::Iter +ator' ) ) { $_tt_list = Template::Config->iterator($_t +t_list) || die $Template::Config::ERROR, "\n"; } ## end unless ( UNIVERSAL::isa( $_tt_list... +)) ( $_tt_value, $_tt_error ) = $_tt_list->get_fi +rst(); eval { $_tt_oldloop = $stash->get('loop') }; $stash->set( 'loop', $_tt_list ); eval { FOR1: while ( !$_tt_error ) { $stash->{'variable'} = $_tt_value; $output .= " \n The variable is set to "; #line 11 "recurse.tt2" $output .= $stash->get('variable'); $output .= " \n "; ( $_tt_value, $_tt_error ) = $_tt_list->get_next(); } ## end while ( !$_tt_error ) }; $stash->set( 'loop', $_tt_oldloop ); die $@ if $@; $_tt_error = 0 if $_tt_error && $_tt_error eq Template::Constants::ST +ATUS_DONE; die $_tt_error if $_tt_error; }; $output .= " \n"; } ## end BLOCK: }; if ($@) { $_tt_error = $context->catch( $@, \$output ); die $_tt_error unless $_tt_error->type eq 'return'; } return $output; }, DEFBLOCKS => { 'recurse' => sub { my $context = shift || die "template sub called without context\n"; my $stash = $context->stash; my $output = ''; my $_tt_error; eval { BLOCK: { $output .= " \n"; $output .= "recursion count: "; #line 3 "recurse.tt2" $output .= $stash->get('counter'); $output .= " \n"; #line 4 "recurse.tt2" $stash->set( 'counter', $stash->get('counter') + + 1 ); #line 5 "recurse.tt2" if ( $stash->get('counter') > 3 ) { $context->throw( 'return', '', \$output ); } #line 6 "recurse.tt2" $output .= $context->process('recurse'); $output .= " \n"; } ## end BLOCK: }; if ($@) { $_tt_error = $context->catch( $@, \$output ); die $_tt_error unless $_tt_error->type eq 'return' +; } return $output; }, }, } );
In reply to Re: H.O.P && aXML
by Anonymous Monk
in thread H.O.P && aXML
by Logicus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |