-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
<!-- 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comma after |
||
in the previous three directories: | ||
|
||
.. code-block:: jinja | ||
|
||
{% include '@theme/header.twig' %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
andRegistering your own namespaces
. Are they correct? Should I fix them too?There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.