[TwigBundle] added a new paths setting to allow configuration of more paths for the filesystem loader (refs #4649)

This commit is contained in:
Fabien Potencier 2012-07-09 17:35:58 +02:00
parent 8f267ada09
commit 39e821c1eb
7 changed files with 10 additions and 3 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
2.1.0
-----
* added a new setting ("paths") to configure more paths for the Twig filesystem loader
* added contextual escaping based on the template file name (disabled if you explicitly pass an autoescape option)
* added a command that extracts translation messages from templates
* added the real template name when an error occurs in a Twig template

View File

@ -115,6 +115,7 @@ class Configuration implements ConfigurationInterface
private function addTwigOptions(ArrayNodeDefinition $rootNode)
{
$rootNode
->fixXmlConfig('path')
->children()
->scalarNode('autoescape')->end()
->scalarNode('base_template_class')->example('Twig_Template')->end()
@ -124,7 +125,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('strict_variables')->end()
->scalarNode('auto_reload')->end()
->scalarNode('optimizations')->end()
->arrayNode('loader_paths')
->arrayNode('paths')
->prototype('variable')->end()
->end()
->end()

View File

@ -60,8 +60,8 @@ class TwigExtension extends Extension
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
if (!empty($config['loader_paths'])) {
foreach ($config['loader_paths'] as $path) {
if (!empty($config['paths'])) {
foreach ($config['paths'] as $path) {
$container->getDefinition('twig.loader')->addMethodCall('addPath', array($path));
}
}

View File

@ -11,6 +11,7 @@
<xsd:sequence>
<xsd:element name="form" type="form" minOccurs="0" maxOccurs="1" />
<xsd:element name="global" type="global" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="path" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="auto-reload" type="xsd:string" />

View File

@ -18,4 +18,5 @@ $container->loadFromExtension('twig', array(
'charset' => 'ISO-8859-1',
'debug' => true,
'strict_variables' => true,
'paths' => array('path1', 'path2'),
));

View File

@ -12,5 +12,7 @@
</twig:form>
<twig:global key="foo" id="bar" type="service" />
<twig:global key="pi">3.14</twig:global>
<twig:path>path1</twig:path>
<twig:path>path2</twig:path>
</twig:config>
</container>

View File

@ -13,3 +13,4 @@ twig:
charset: ISO-8859-1
debug: true
strict_variables: true
paths: [path1, path2]