Skip to content

Added a note about configuring several paths under the same namespace #3877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions cookbook/templating/namespaced_paths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple Paths per Namespace (everything should be capitalized except from closed-class words)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand this comment. The original headings of this article were: How to use and Register namespaced Twig Paths and Registering your own namespaces. Are they correct? Should I fix them too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, those are indeed also incorrect. They should be "How to Use and Register Namespaced Twig Paths" and "Registering your own Namespaces"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @wouterj! Everything is fixed now.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

<!-- app/config/config.xml -->
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed if you don't use the xsi:schemeLocation attribute

xmlns:twig="http://symfony.com/schema/dic/twig"
>

<twig:config debug="%kernel.debug%" strict-variables="%kernel.debug%">
<twig:path namespace="theme">%kernel.root_dir%/../vendor/acme/themes/theme1</twig:path>
<twig:path namespace="theme">%kernel.root_dir%/../vendor/acme/themes/theme2</twig:path>
<twig:path namespace="theme">%kernel.root_dir%/../vendor/acme/themes/common</twig:path>
</twig:config>
</container>

.. 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comma after Now

in the previous three directories:

.. code-block:: jinja

{% include '@theme/header.twig' %}