-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TwigBundle] Improve the overriding of bundle templates #24264
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
Conversation
a1fed5b
to
32010f8
Compare
I just updated the description to clarify the proposal, it's not about At the same time, you can from a controller or anywhere to load directly the template of the bundle or the overridden one in your app, without create extra templates or extra configuration to achieve it. |
Feat. freeze is coming :) also we can use some preffix or suffix to achieve it, WDYT? ping @fabpot, @javiereguiluz |
I don't dislike the idea ... but I'm not sold on it either. My concern is that you'll have two almost identical namespaces that are completely different: |
Other proposal that is easy to remember?
This namespace should be used only to avoid the circular reference. |
I share @javiereguiluz' concerns though I also do not have a better proposal. |
Some random proposals: {% extends 'parent@Foo/layout.html.twig' %}
{% extends '@@Foo/layout.html.twig' %}
{% extends '@Foo/layout.html.twig', { parent: true } %} |
@javiereguiluz only the second one |
It's not intuitive anyway, so we need document it. |
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.
but my own preference would actually be
{% extends '@!Foo/layout.html.twig' %}
@ogizanagi's suggestion sounds good to me too. |
Perfect! I like this too, changed to |
52ddda0
to
0a658c6
Compare
Thank you @yceruto. |
…s (yceruto) This PR was merged into the 3.4 branch. Discussion ---------- [TwigBundle] Improve the overriding of bundle templates | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17557 | License | MIT | Doc PR | - ### [Overriding a Template that also extends itself](https://twig.symfony.com/doc/2.x/recipes.html#overriding-a-template-that-also-extends-itself) Now that bundles inheritance is deprecated and removed (#24160, #24161), I'm wondering if we can solve this old issue defining an exclusive namespace only for root bundles in `3.4` just bundles in `4.0`: ```yaml twig: paths: # adding paths behind the scene into TwigExtension app/Resources/FooBundle/views: Foo vendor/acme/foo-bundle/Resources/views: Foo vendor/acme/foo-bundle/Resources/views: !Foo # exclusive ``` Thus, one can decide when use the exclusive namespace to avoid the issue and then [we could to say also](http://symfony.com/doc/current/templating/overriding.html): > To override the bundle template partially (which contains `block`) creates a new `index.html.twig` template in `app/Resources/AcmeBlogBundle/views/Blog/index.html.twig` and extends from `@!AcmeBlogBundle/Blog/index.html.twig` to customize the bundle template: ```twig {# app/Resources/FooBundle/views/layout.html.twig #} {# this does not work: circular reference to itself #} {% extends '@Foo/layout.html.twig' %} {# this will work: load bundle layout template #} {% extends '@!Foo/layout.html.twig' %} {% block title 'New title' %} ``` I hear other suggestions about the excluse namespace. We will need to update http://symfony.com/doc/current/templating.html#referencing-templates-in-a-bundle too to add this convention. WDYT? Commits ------- 0a658c6 Add exclusive Twig namespace for bundles path
@yceruto or anyone else with some free time: I broke tests when merging this into master, could you have a look please? |
@nicolas-grekas Still broken? |
yes |
The code in symfony/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php Lines 118 to 121 in f46ab8e
and Travis pass (at least for
taken from https://travis-ci.org/symfony/symfony/builds/281245817 |
Oh nice sorry, I didn't break it because if this PR, but another one, NVM :) |
Overriding a Template that also extends itself
Now that bundles inheritance is deprecated and removed (#24160, #24161), I'm wondering if we can solve this old issue defining an exclusive namespace only for root bundles in
3.4
just bundles in4.0
:Thus, one can decide when use the exclusive namespace to avoid the issue and then we could say also:
I hear other suggestions about the excluse namespace.
We will need to update http://symfony.com/doc/current/templating.html#referencing-templates-in-a-bundle too to add this convention.
WDYT?