Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c8e1327

Browse filesBrowse files
committed
Add default templates directory and option to configure it
1 parent ade060e commit c8e1327
Copy full SHA for c8e1327

File tree

10 files changed

+27
-3
lines changed
Filter options

10 files changed

+27
-3
lines changed

‎src/Symfony/Bundle/TwigBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* deprecated `Symfony\Bundle\TwigBundle\Command\DebugCommand`, use `Symfony\Bridge\Twig\Command\DebugCommand` instead
88
* deprecated relying on the `ContainerAwareInterface` implementation for `Symfony\Bundle\TwigBundle\Command\LintCommand`
9+
* added option to configure default path templates (via `default_path`)
910

1011
3.3.0
1112
-----

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
130130
->booleanNode('strict_variables')->end()
131131
->scalarNode('auto_reload')->end()
132132
->integerNode('optimizations')->min(-1)->end()
133+
->scalarNode('default_path')
134+
->info('The default path used to load templates')
135+
->defaultValue('%kernel.project_dir%/templates')
136+
->end()
133137
->arrayNode('paths')
134138
->normalizeKeys(false)
135139
->useAttributeAsKey('paths')

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function load(array $configs, ContainerBuilder $container)
109109
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']);
110110
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);
111111

112-
$bundleHierarchy = $this->getBundleHierarchy($container);
112+
$bundleHierarchy = $this->getBundleHierarchy($container, $config);
113113

114114
foreach ($bundleHierarchy as $name => $bundle) {
115115
$namespace = $this->normalizeBundleName($name);
@@ -130,6 +130,11 @@ public function load(array $configs, ContainerBuilder $container)
130130
}
131131
$container->addResource(new FileExistenceResource($dir));
132132

133+
if (file_exists($dir = $container->getParameterBag()->resolveValue($config['default_path']))) {
134+
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
135+
}
136+
$container->addResource(new FileExistenceResource($dir));
137+
133138
if (!empty($config['globals'])) {
134139
$def = $container->getDefinition('twig');
135140
foreach ($config['globals'] as $key => $global) {
@@ -174,7 +179,7 @@ public function load(array $configs, ContainerBuilder $container)
174179
}
175180
}
176181

177-
private function getBundleHierarchy(ContainerBuilder $container)
182+
private function getBundleHierarchy(ContainerBuilder $container, array $config)
178183
{
179184
$bundleHierarchy = array();
180185

@@ -192,6 +197,11 @@ private function getBundleHierarchy(ContainerBuilder $container)
192197
}
193198
$container->addResource(new FileExistenceResource($dir));
194199

200+
if (file_exists($dir = $container->getParameterBag()->resolveValue($config['default_path']).'/bundles/'.$name)) {
201+
$bundleHierarchy[$name]['paths'][] = $dir;
202+
}
203+
$container->addResource(new FileExistenceResource($dir));
204+
195205
if (file_exists($dir = $bundle['path'].'/Resources/views')) {
196206
$bundleHierarchy[$name]['paths'][] = $dir;
197207
}

‎src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<xsd:attribute name="debug" type="xsd:string" />
2727
<xsd:attribute name="strict-variables" type="xsd:string" />
2828
<xsd:attribute name="exception-controller" type="xsd:string" />
29+
<xsd:attribute name="default-path" type="xsd:string" />
2930
</xsd:complexType>
3031

3132
<xsd:complexType name="date">

‎src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'charset' => 'ISO-8859-1',
1818
'debug' => true,
1919
'strict_variables' => true,
20+
'default_path' => '%kernel.root_dir%/templates',
2021
'paths' => array(
2122
'path1',
2223
'path2',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a layout
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a layout

‎src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
77
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
88

9-
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
9+
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true" default-path="%kernel.root_dir%/templates">
1010
<twig:form-theme>MyBundle::form.html.twig</twig:form-theme>
1111
<twig:global key="foo" id="bar" type="service" />
1212
<twig:global key="baz">@@qux</twig:global>

‎src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ twig:
1313
charset: ISO-8859-1
1414
debug: true
1515
strict_variables: true
16+
default_path: '%kernel.root_dir%/templates'
1617
paths:
1718
path1: ''
1819
path2: ''

‎src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ public function testTwigLoaderPaths($format)
182182
}
183183
}
184184

185+
//dump($paths); die;
186+
185187
$this->assertEquals(array(
186188
array('path1'),
187189
array('path2'),
@@ -196,6 +198,7 @@ public function testTwigLoaderPaths($format)
196198
array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'Twig'),
197199
array(__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'Twig'),
198200
array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'),
201+
array(__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'),
199202
array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'),
200203
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
201204
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
@@ -205,6 +208,7 @@ public function testTwigLoaderPaths($format)
205208
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
206209
array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
207210
array(__DIR__.'/Fixtures/Resources/views'),
211+
array(__DIR__.'/Fixtures/templates'),
208212
), $paths);
209213
}
210214

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.