+ -
当前位置:首页 → 问答吧 → 关于HTML::Template中嵌套LOOP的问题

关于HTML::Template中嵌套LOOP的问题

时间:2010-08-27

来源:互联网

最近在使用HTML::Template模块,觉得挺好用的,但是遇到了一个问题。
在嵌套的循环中,
for{
   for{
         @loop1;
   }
   @loop2;
}
在接下来向模板传值的时候遇到问题了。
我写做    $template->param( LOOP_ONE => [\@loop1,  LOOP_TWO => \@loop2]);
可是一直会报错,不知道哪位高手能赐教一下,谢谢

作者: Wayne_sama   发布时间: 2010-08-27



QUOTE:
for{
   for{
         @loop1;
   }
   @loop2;
}


这是模板?
  1. $template->param( LOOP_ONE => [\@loop1,  LOOP_TWO => \@loop2]);
复制代码
中括号不对?

作者: ynchnluiti   发布时间: 2010-08-27



QUOTE:
       <TMPL_LOOP>s within <TMPL_LOOP>s are fine and work as you would expect.  If the syntax for the "param()" call has you stumped, here's an example of a param call with one nested loop:
         $template->param(LOOP => [
                                   { name => 'Bobby',
                                     nicknames => [
                                                   { name => 'the big bad wolf' },
                                                   { name => 'He-Man' },
                                                  ],
                                   },
                                  ],
                         );
       Basically, each <TMPL_LOOP> gets an array reference.  Inside the array are any number of hash references.  These hashes contain the name=>value pairs for a single pass over the loop template.
       Inside a <TMPL_LOOP>, the only variables that are usable are the ones from the <TMPL_LOOP>.  The variables in the outer blocks are not visible within a template loop.  For the computer-science geeks among you, a <TMPL_LOOP> introduces a new scope much like a perl subroutine call. ...


文档

作者: ynchnluiti   发布时间: 2010-08-27