-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Made TemplateNameParser able to parse templates in the @-notation (#5660) #7818
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
@bschussek I see an issue here: as you are parsing the |
@stof Yes, you're right. We have to replace the bundle check by a namespace check. But we can only do this if we also register the namespaces in the Templating component (apart from Twig). |
@bschussek currently, the TwigBundle FilesystemLoader is using the parser and then fallback to using the string itself as template name directly. This works well and does not break the Twig features. All we need is allowing the TwigEngine to work this way too instead of forcing to have a bundle notation IMO. |
If I register a namespace path |
Regarding the Bundle suffix, we tried this in early alpha some time i remember and then unilaterally wanted to move back to the Bundle suffix one alpha later. |
@beberlei I'm slow today, what's your point? :) Are you saying we should bring back the "Bundle" suffix here as well? |
@bschussek Bring back? The todo says you are evaluating to remove it here, did you already? |
Oh, this is badly named then :) The Bundle suffix is already dropped for this notation. The questions is whether we bring it back in 2.3 (now that the syntax is not that wide-spread yet) or to leave this inconsistency in at least until 3.0. Ping @fabpot |
A very interesting proposal came up in the FIG that could solve the problems mentioned here in a much more generic scope: https://groups.google.com/forum/?fromgroups#!topic/php-fig/WMaKNNhHZJw |
👍 for this PR, in Sourcefabric we wait for that, tell if we can help! |
Closing this. The same functionality - but better - will be delivered by webmozart/symfony-puli-bundle at some point. |
This PR adds the ability to handle Twig's new template name syntax (see fabpot/Twig#772 and #5660) to the
TemplateNameParser
class. Before, the syntax could only be used in Twig's own functionality, such as theextend
orinclude
statements. Now, the syntax can be used anywhere in a Symfony application, such as when returning from a Controller, the@Template
annotation or with PHP Templating. The old syntax "bundle:controller:template" is still supported, but can be completely replaced*.Examples:
index.html.twig
::index.html.twig
Foo/bar.html.php
:Foo:bar.html.php
@AcmeDemo/test.html.twig
AcmeDemoBundle::test.html.twig
@AcmeDemo/Post/create.html.php
AcmeDemoBundle:Post:create.html.php
* The support for bundle inheritance is still missing for Twig: #6918
Benchmarks
Performance benchmark:
Scripts:
benchmark-old.php
benchmark-new.php
benchmark-new2.php
Remaining Concerns
My remaining concern is about the convention to drop the bundle suffix in the new syntax. I dislike it for three reasons:
@AcmeDemo/index.html.twig
vs.@AcmeDemoBundle/Resources/config/routing.yml
)@AcmeDemo/index.html.twig
vs.AcmeDemoBundle/index.html.twig
)@Monolog/template.html.twig
but for the second as well, creating a conflict)@fabpot stated in #5660 that an advantage of dropping the "Bundle" suffix is making the namespaces
I disagree. When I load MonologBundle into my non-Symfony application, it makes sense that the namespace is "MonologBundle".
The second question we have to solve is whether we change the logical template name (
TemplateReference::getLogicalName()
) to the new syntax as well. I left it at the old syntax for now because I don't know what the BC implications would be.