ねもぷらす

ふぁいんでぃんぐねもの日記。プログラミングとか育児とか

Template-ToolKit ではろーわーるど

  • test.pl
#!/usr/local/bin/perl -w

use warnings;
use strict;
use Template;

eval{
  ## Template-ToolKit
  my $ttConfig = { INCLUDE_PATH => './' };
  my $tt = Template->new( $ttConfig );
  my $output;
  my $param = {
    message => 'hello!' ,
    test    => 'world!!',
  };

  $tt->process( 'test.tt', { param => \%{$param} }, \$output ) ;

  print $output;
};if(my $error = $@){
  print "$error\n";
}

1;
__END__
  • test.tt
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>[% param.message %] [% param.test %]</title>
  </head>
  <body>
    <h1>[% param.message %]</h1>
    <h2>[% param.test %]</h2>
  </body>
</html>