问题
I've structured my website with a separate directory for each component (i.e. page).
/var/www/components/component_1/
/var/www/components/component_2/
/var/www/components/component_3/
Within each directory, I have a controller, a model, and a Twig template. A typical template which might be located at /var/www/components/component_2/templates/myTemp.html looks like the following:
{% extends "base.html" %}
bla bla bla
I have several base templates. Unlike the child templates, I wish these to be located in /var/www/templates/
How do I specify two locations when extending Twig templates?
回答1:
Just take a look at Twig Loader Filesystem http://twig.sensiolabs.org/doc/api.html#twig-loader-filesystem
So can do something like:
$loader = new Twig_Loader_Filesystem(array('/var/www/components/component_1/templates', '/var/www/templates'));
$twig = new Twig_Environment($loader);
echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
来源:https://stackoverflow.com/questions/25974568/how-do-i-specify-two-locations-for-twig-templates