define custom filesystem path for twig templates

前端 未结 3 1503
攒了一身酷
攒了一身酷 2020-12-21 14:07

I\'ve already read How does Symfony2 detect where to load templates from? and another ton of articles on the web

The question was quite similar to mine, but the answ

3条回答
  •  無奈伤痛
    2020-12-21 14:11

    To add a directory for twig templates I do this:

    chdir(__DIR__);
    $this->container->get('twig.loader')->addPath('../../../../web/templates/', $namespace = '__main__');
    

    this allows me to put twig templates in a folder called 'templates' in the web folder and symfony 2.3 has no issues loading them.

提交回复
热议问题