A method for changing INCLUDE_PATH in Template::To

2019-06-12 04:02发布

If I have a preloaded Template::Toolkit object, in mod_perl enviroment for example, is there any way to change INCLUDE_PATH array without recreating the object?

1条回答
唯我独甜
2楼-- · 2019-06-12 04:38

I use the Template::Provider for this

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"]);
查看更多
登录 后发表回答