2009-08-15 29 views

回答

7

我認爲它的EXPOSE_BLOCKS選項,你可能在之後?

use strict; 
use warnings; 
use Template; 

my $tt = Template->new({ 
    INCLUDE_PATH => '.', 
    EXPOSE_BLOCKS => 1, 
}); 

$tt->process('test.tt/header', { tit => 'Weekly report' }); 

for my $day qw(Mon Tues Weds Thurs Fri Sat Sun) { 
    $tt->process('test.tt/body', { day => $day, result => int rand 999 }); 
} 

$tt->process('test.tt/footer', { tit => '1st Jan 1999' }); 

 

test.tt:

[% BLOCK header %] 
[% tit %] 
[% END %] 

[% BLOCK body %] 
* Results for [% day %] are [% result %] 
[% END %] 

[% BLOCK footer %] 
Correct for week commencing [% tit %] 
[% END %] 

 

會產生這一報告(與隨機數):

週報

  • 結果星期一是728

  • 結果星期二363

  • 結果威爾是772

  • 結果週四是864個

  • 結果星期五是490

  • 個結果週六88個

  • 結果太陽是887

糾正本週開始1999年1月

 

希望有所幫助。

+0

謝謝!你知道我在哪裏可以找到Template Toolkit配置選項的完整列表嗎?這個列表中沒有提到EXPOSE_BLOCKS:http://template-toolkit.org/docs/manual/Config.html – 2009-08-16 07:41:36

+0

這可能是最好的列表,但不幸像你注意到EXPOSE_BLOCKS從它丟失:(我可能選擇了EXPOSE_BLOCKS從Perl模板工具包(http://template-toolkit.org/book.html)中可以看出,只是通過索引輕彈它說的是第69頁......嗯,這個例子非常簡單,但它在那裏被提及。 – draegtun 2009-08-16 08:58:21