A method for changing INCLUDE_PATH in Template::Toolkit on the FLY

北战南征 提交于 2019-12-23 05:21:10

问题


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:


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"]);


来源:https://stackoverflow.com/questions/4186740/a-method-for-changing-include-path-in-templatetoolkit-on-the-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!