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 29863f1

Browse filesBrowse files
committed
Added a note about configuring several paths under the same namespace
1 parent 9f26da8 commit 29863f1
Copy full SHA for 29863f1

File tree

Expand file treeCollapse file tree

1 file changed

+53
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+53
-0
lines changed

‎cookbook/templating/namespaced_paths.rst

Copy file name to clipboardExpand all lines: cookbook/templating/namespaced_paths.rst
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,56 @@ called ``sidebar.twig`` in that directory, you can use it easily:
8181
.. code-block:: jinja
8282
8383
{% include '@foo_bar/sidebar.twig' %}
84+
85+
Multiple paths per namespace
86+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87+
88+
You can also assign several paths to the same template namespace. The order in
89+
which paths are configured is very important, because Twig will always load
90+
the first template that exists, starting from the first configured path. This
91+
feature can be used as a fallback mechanism to load generic templates when the
92+
specific template doesn't exist.
93+
94+
.. code-block:: yaml
95+
96+
# app/config/config.yml
97+
twig:
98+
# ...
99+
paths:
100+
"%kernel.root_dir%/../vendor/acme/themes/theme1": theme
101+
"%kernel.root_dir%/../vendor/acme/themes/theme2": theme
102+
"%kernel.root_dir%/../vendor/acme/themes/common": theme
103+
104+
.. code-block:: xml
105+
106+
<!-- app/config/config.xml -->
107+
<?xml version="1.0" ?>
108+
<container xmlns="http://symfony.com/schema/dic/services"
109+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
110+
xmlns:twig="http://symfony.com/schema/dic/twig"
111+
>
112+
113+
<twig:config debug="%kernel.debug%" strict-variables="%kernel.debug%">
114+
<twig:path namespace="theme">%kernel.root_dir%/../vendor/acme/themes/theme1</twig:path>
115+
<twig:path namespace="theme">%kernel.root_dir%/../vendor/acme/themes/theme2</twig:path>
116+
<twig:path namespace="theme">%kernel.root_dir%/../vendor/acme/themes/common</twig:path>
117+
</twig:config>
118+
</container>
119+
120+
.. code-block:: php
121+
122+
// app/config/config.php
123+
$container->loadFromExtension('twig', array(
124+
'paths' => array(
125+
'%kernel.root_dir%/../vendor/acme/themes/theme1' => 'theme',
126+
'%kernel.root_dir%/../vendor/acme/themes/theme2' => 'theme',
127+
'%kernel.root_dir%/../vendor/acme/themes/common' => 'theme',
128+
);
129+
));
130+
131+
Now you can use the same ``@theme`` namespace to refer to any template located
132+
in the previous three directories:
133+
134+
.. code-block:: jinja
135+
136+
{% include '@theme/header.twig' %}

0 commit comments

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