0

如果我有一个预加载的 Template::Toolkit 对象,例如在 mod_perl 环境中,有没有办法在不重新创建对象的情况下更改 INCLUDE_PATH 数组?

4

1 回答 1

2

我为此使用 Template::Provider

my $template_config = {
        INCLUDE_PATH => "/path/to/templates",
        ENCODING => 'utf8',
};



# Create template_provider manually so that we can manipulate template path
# later.
my $template_provider = Template::Provider->new($template_config);

  my $tt = Template->new({
      LOAD_TEMPLATES => [$template_provider ],
      PRE_CHOMP    => 2,
      POST_CHOMP   => 3,
      TRIM         => 1,
      ENCODING     => 'utf8',
    }) || die $Template::ERROR;


# somewhere else later
       $template_provider->include_path([
         "$dir/templates/$language",
         "$dir/templates"]);
于 2010-11-15T18:55:53.433 回答