-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Added syntax for obtaining the original bundle #2202
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
I think its good to address this missing feature. I am not sure I like the syntax as |
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.
Should proberly be next instead of end.
As noted in the comment on you diff i think it should take the next match and not the last match. This would make more sense and not ignore kill the cascading lookup. |
If its next then maybe a git-sh |
…original bundle is required
@henrikbjorn I think that
Each template extends the previous template: {# app/Resources/FooBarBundle/index.html.twig #}
{% extends "^FooBundle::index.html.twig" %}
---
{# bundles/FooBarBundle/Resources/index.html.twig #}
{% extends "^FooBundle::index.html.twig" %} {# next() return wrong bundle #}
---
{# bundles/FooBundle/Resources/index.html.twig #}
<html> The simplest and explicit solution is via syntax for original bundle: {# app/Resources/FooBarBundle/index.html.twig #}
{% extends ["!FooBarBundle::index.html.twig", "!FooBundle::index.html.twig"] %}
---
{# bundles/FooBarBundle/Resources/index.html.twig #}
{% extends "!FooBundle::index.html.twig" %}
---
{# bundles/FooBundle/Resources/index.html.twig #}
<html> |
It shouldnt change the bundle then. Just jump to the next path in the list. {# bundles/FooBarBundle/Resources/index.html.twig #} would be able to extend its parent if unless it is an extending bundle. |
Some ideas for notation: |
or just |
|
how about |
|
I'm a fan of using one character to get to the end of the inheritance tree (to the discussion of Regarding syntax, |
During today's IRC meeting, it has been decided to not add this feature as we don't have that many use cases and it adds some non-trivial complexity. I've added a doc ticket to update documentation about how to solve the issue described here (symfony/symfony-docs#752). |
@fabpot I would say there are very many use cases for this feature, basically every bundle which defines an "entrypoint" template (by entrypoint I mean a template which is rendered directly) is a subject to this feature. Introducing a one-liner side-template is an overkill, imo. What do you mean under increased complexity? That it is hard to understand for a newcomer (can be easily taken care of with additional documentation under template inheritance) or that it adds an overhead to locating resources (haven't benchmarked but I doubt it's significant)? I encourage to re-address this issue, seems like a should-have to me .. |
The issue is that if we do introduce such a syntax for the "simple case", we also need to ensure that it remains consistent for the "complex case". The simple case: Here its obvious which template is meant when referencing the previous one, since there is only one. The complex case: Now does the person mean to reference the original or the previous extended template? As you can imagine it can get more complex if the chain consists of 3 or more templates. |
Well, just because we haven't yet found a nice solution for complex scenarios does not mean we should discard the feature altogether. Your own proposed git-style caret seems already a good start. Put as many as you'd like and as many steps ahead the lookup is done. While I agree, that it might be a bit fragile in case intermediary layers are introduced, that is a drawback we need to find a solution for or just accept. Another idea just off the top of my head, which I think solves the fragility mentioned above. How about prefixing the caret with desired bundle name:
|
It's now a few years later and the use composer with vendors bundles a lot. We currently don't have a way to extend one block of a vendor template (even when we are the vendor ourselfes). We always have to copy the complete template, if we want to add something, for example an extra information block in a CMS for a specific website. So maybe it's time to reopen this issue and provide a way to extend a vendor template? |
+1 for reopening. @fabpot Could you check this again? There are LOTS of usecases when this is needed. For example, we override many templates of SonataAdmin. Without this, we should copy every single file and override few lines. |
@marijnotte and @nick4fake Take a look at the TemplateNameParser in boekkooi/twig-jack-bundle |
@boekkooi thank you very much, this is exactly what we need |
One of the possible ways to solve #1966