繁体   English   中英

在Twig中动态加载模板目录

[英]Load template directory dynamic in Twig

我在项目中使用Twig,没有将Symfony用作PHP框架。

这是我的构造函数:

    $this->_template_dir []= '/views/';
    $this->_template_dir []= 'modules/comments/views/';

    $loader = new Twig_Loader_Filesystem($this->_template_dir);

    $this->_twig = new Twig_Environment($loader, array(
            'cache' => $this->_cache_dir,
            'debug' => TRUE,
            'auto_escape' => FALSE,
            'autoescape' => FALSE,
            'auto_reload' => ! (ENVIRONMENT == 'production')
    ));

有没有办法在构造函数之后设置模板目录? 就像一个方法:

$this->_twig->addTemplateDir('new_folder');

我没有在文档中找到任何东西。

你应该能够使用

$this->_twig->setLoader($this->_template_dir[0])

启动树枝后

Twig_Loader_Filesystem具有方法addPath()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM