From 29863f11ba788c8dba78c02032ec49e92fd95e3c Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 26 May 2014 16:00:12 +0200 Subject: [PATCH 1/4] Added a note about configuring several paths under the same namespace --- cookbook/templating/namespaced_paths.rst | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/cookbook/templating/namespaced_paths.rst b/cookbook/templating/namespaced_paths.rst index 7f4bd6a56cc..bc997efbbda 100644 --- a/cookbook/templating/namespaced_paths.rst +++ b/cookbook/templating/namespaced_paths.rst @@ -81,3 +81,56 @@ called ``sidebar.twig`` in that directory, you can use it easily: .. code-block:: jinja {% include '@foo_bar/sidebar.twig' %} + +Multiple paths per namespace +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also assign several paths to the same template namespace. The order in +which paths are configured is very important, because Twig will always load +the first template that exists, starting from the first configured path. This +feature can be used as a fallback mechanism to load generic templates when the +specific template doesn't exist. + + .. code-block:: yaml + + # app/config/config.yml + twig: + # ... + paths: + "%kernel.root_dir%/../vendor/acme/themes/theme1": theme + "%kernel.root_dir%/../vendor/acme/themes/theme2": theme + "%kernel.root_dir%/../vendor/acme/themes/common": theme + + .. code-block:: xml + + + + + + + %kernel.root_dir%/../vendor/acme/themes/theme1 + %kernel.root_dir%/../vendor/acme/themes/theme2 + %kernel.root_dir%/../vendor/acme/themes/common + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('twig', array( + 'paths' => array( + '%kernel.root_dir%/../vendor/acme/themes/theme1' => 'theme', + '%kernel.root_dir%/../vendor/acme/themes/theme2' => 'theme', + '%kernel.root_dir%/../vendor/acme/themes/common' => 'theme', + ); + )); + +Now you can use the same ``@theme`` namespace to refer to any template located +in the previous three directories: + +.. code-block:: jinja + + {% include '@theme/header.twig' %} From 857c6cda2ca85fc3f158936ccf568f17188a8415 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 26 May 2014 16:26:06 +0200 Subject: [PATCH 2/4] Minor simplification of the XML code --- cookbook/templating/namespaced_paths.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/cookbook/templating/namespaced_paths.rst b/cookbook/templating/namespaced_paths.rst index bc997efbbda..d1aa4201616 100644 --- a/cookbook/templating/namespaced_paths.rst +++ b/cookbook/templating/namespaced_paths.rst @@ -106,7 +106,6 @@ specific template doesn't exist. From 40524ca870f168589ba6012c3bd3a3296a512233 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 26 May 2014 16:55:33 +0200 Subject: [PATCH 3/4] Fixed the case of the headings --- cookbook/templating/namespaced_paths.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbook/templating/namespaced_paths.rst b/cookbook/templating/namespaced_paths.rst index d1aa4201616..48580f4d78b 100644 --- a/cookbook/templating/namespaced_paths.rst +++ b/cookbook/templating/namespaced_paths.rst @@ -1,7 +1,7 @@ .. index:: single: Templating; Namespaced Twig Paths -How to use and Register namespaced Twig Paths +How to Use and Register Namespaced Twig Paths ============================================= .. versionadded:: 2.2 @@ -33,7 +33,7 @@ Both paths are valid and functional by default in Symfony2. As an added bonus, the namespaced syntax is faster. -Registering your own namespaces +Registering your own Namespaces ------------------------------- You can also register your own custom namespaces. Suppose that you're using @@ -82,7 +82,7 @@ called ``sidebar.twig`` in that directory, you can use it easily: {% include '@foo_bar/sidebar.twig' %} -Multiple paths per namespace +Multiple Paths per Namespace ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also assign several paths to the same template namespace. The order in From fb5388c5675c36ed602ace4c455c7935ec36ff09 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 26 May 2014 17:52:36 +0200 Subject: [PATCH 4/4] Added a comma --- cookbook/templating/namespaced_paths.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/templating/namespaced_paths.rst b/cookbook/templating/namespaced_paths.rst index 48580f4d78b..f26ba8a3237 100644 --- a/cookbook/templating/namespaced_paths.rst +++ b/cookbook/templating/namespaced_paths.rst @@ -127,7 +127,7 @@ specific template doesn't exist. ); )); -Now you can use the same ``@theme`` namespace to refer to any template located +Now, you can use the same ``@theme`` namespace to refer to any template located in the previous three directories: .. code-block:: jinja