【问题标题】:Display array in multi-column table using template tookit?使用模板工具包在多列表中显示数组?
【发布时间】:2013-05-03 02:56:39
【问题描述】:

我有一组电话号码。我想在表格中显示这些数字,每行 5 个数字。我可以在 Template Toolkit 中执行此操作而不修改我的数据结构吗?

【问题讨论】:

    标签: perl template-toolkit


    【解决方案1】:

    可以使用插件Template::Plugin::Table

    [% USE table(phone_numbers, cols=5) %]
    
    [% FOREACH row IN table.rows %]
       [% FOREACH item IN row %]
          [% item %]
       [% END %]
    [% END %]
    

    phone_numbers 是对应传递给模板工具包的电话号码数组的引用。示例:

    ...
    $data->{phone_numbers} = \@phone_numbers;
    
    $template->process('example.tmpl', $data) 
       || die "Template processing failed: ", $template->error(), "\n";
    

    【讨论】:

      猜你喜欢
      • 2015-08-01
      • 2011-01-15
      • 2020-12-11
      • 2011-10-05
      • 2016-10-14
      • 1970-01-01
      • 2012-09-06
      • 2019-01-03
      • 1970-01-01
      相关资源
      最近更新 更多