他のテンプレートを取り込む
調べたらすぐ見つかった。INCLUDEディレクティブを使うらしい。
読んだだけじゃわからんのでサンプルを書いてみる
tt_include_test.pl
use strict; use warnings; use Template; my $template = Template->new(); my $tt_file = 'tt_include_test.tt'; my $params = { hoge1 => "temp1", hoge2 => "temp2", }; $template->process($tt_file,$params) || die $template->error();
で、以下の二つのテンプレートを書いて、同じディレクトリに置いてみる。
tt_include_test.tt
これは[% hoge1 %]です。 [% INCLUDE 'tt_include_test2.tt' %]
tt_include_test2.tt
これは[% hoge2 %]です。
で動かしてみた。
>perl -w tt_include_test.pl これはtemp1です。 これはtemp2です。
おぉ、あっさり出来た。