Chinaunix

标题: 关于HTML::Template中嵌套LOOP的问题 [打印本页]

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

这是模板?
  1. $template->param( LOOP_ONE => [\@loop1,  LOOP_TWO => \@loop2]);
复制代码
中括号不对?
作者: ynchnluiti    时间: 2010-08-27 20:31
       <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. ...

文档
作者: lillainpcy    时间: 2011-01-06 11:07
我也碰到相同问题,加了{},还是不对。

$template->param( LOOP_ONE => [{\@loop1,  LOOP_TWO => \@loop2}]);

运行后提示:

HTML::Template->output() : fatal error in loop output : HTML::Template : Attempt to set nonexistent parameter 'array(0x3
609db' - this parameter name doesn't match any declarations in the template file : (die_on_bad_params => 1) at C:/Perl
/site/lib/HTML/Template.pm line 3068
作者: lillainpcy    时间: 2011-01-06 13:16
有人回回贴吗?
作者: xufinal    时间: 2011-01-06 14:29
<TMPL_LOOP NAME=A>
      <TMPL_LOOP NAME=B>
      </TMPL_LOOP>
</TMPL_LOOP>


A =  \@A
B须放在@A里
$B{B}=\@B;
$A[0]=\%B;




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2