-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] Introduce new template namespaces for bundles #11051
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
Comments
Why not go the other way round and also allow resources to be specified without suffix |
@Tobion Are you suggesting not making the If you do mean requiring
If we did these, then suddenly the explicit/long way isn't long at all:
I don't take these changes lightly (we would of course protect BC, but changes like this affect documentation, blog posts, etc), but I think we should really ask what the "best" way is (we now have years of experience using all of this). And then figure out if we can do the "best" way without breaking BC. |
@weaverryan the |
@weaverryan No I was suggesting to remove the bundle suffix also from other resource references. |
@stof Ah, good catch. But still, we could easy and safely assume the HTML escape format when there is no format. @Tobion we once a long time ago removed the Bundle suffix, and then instantly all hated it :). "AcmeDemo" just wasn't clear - it wasn't obvious it was a bundle anymore. But I think anything is worth discussing :). |
My 10c: I think it should always be the I was going to say it should be the "Easy Proposal" but then realised that resources aren't always templates... so could come from a directory other than views. The Aggressive Proposal is completely safe, no matter what resource/template/etc is being requested. I think keeping Bundle in the bundle name is important for consistency (& less magic). I also think the template type suffix should be there as well to make it explicit and consistent. So I think the example in the first post should be: |
Isn't the {% javascripts '@AcmeFooBundle/public/js/*' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %} $this->render("@AcmeFooBundle/views/Test/a.html.twig"); |
@apfelbox Yes, the What you're saying is logical, but I don't think it is clear. It would also break backwards-compatability, so I don't think we can actually do it. I would rather recommend that we move things (views, config) out of the @cjunge-work I would be ok with the |
From what have been said we currently have 3 ways of naming items using the namespaced way:
It's obvious that the Assetic naming and the configuration naming are built based on the combination of "@NameOfMyBundle" + "path to the resource". So if we really want to fix this issue from a UX point of view, why don't we just make Twig stick to this pattern ? In this case we would have something like
Pros :
Cons :
|
it indeed breaks BC (the WebProfilerBundle is using the current syntax). And longer paths are a drawback IMO |
I agree with @apfelbox that the |
@stof You're saying there's a BC break in @iamdto proposal? Can you give some more details? I see @Tobion @apfelbox I don't disagree with the proposal to make Thanks for everyone's thoughts! |
@weaverryan I can't really follow you on the BC part: In your first paragraph you ask @stof to clarify why he thinks @Tobion's proposal isn't BC and in the second paragraph you explain why @Tobion's proposal isn't BC.
I don't like this. The I like the Let me throw in another idea: Abandon the # routing.yml
_acme_demo:
resource: /acme/demo-bundle/config/routing.yml |
Just for curiosity I was looking at how do other technologies allow to access resources and I wanted to share three quick examples for comparison: Objective-C
C#
Java / Spring Framework
Based on these examples, we could think of new notations: Explicit the type of resource you are loading
Allow to reference both the Resources/ and the root of the bundle
|
|
@weaverryan I agree with @wouterj : I think that moving the What I especially like about the
About the BC break: we shouldn't break BC for no gain. But to me it seems that this would be a good and big goal to achieve and we have 3.0 for BC breaks. |
An additional note: this would be a BC break which on one hand has a quite large impact, but on the other hand is easily fixable (probably in an automated way). |
Hi guys! I wanted to keep this moving forward. Here is a summary:
It seems that we have a few competing ideas:
I'd like to not break BC mostly because it means we could put something into Symfony 2.6, whereas I think a BC break would need to be in 3.0 (which is fine, but would mean waiting). I also thought about using something other than Thanks! |
I don't want to remember the bundle name ,so I wrote a new class to replace render function |
note that the current |
@alan-zhang- the issue with this is that the name of the template would need to know the location of the code using it to be able to resolve it. But PHP strings are not contextual. You cannot know where they have been created. |
Why not |
@fedir Twig allows you to have any output format you want. In my projects, I have some templates outputing plain text (for emails) and I have have a few templates output less markup. TwigBundle will use the |
@stof Maybe we can make render function get the bundle name automatically. It's really a pain to remember the bundle name.
|
@alan-zhang- this could be a shortcut method in the controller, but it would not make |
@stof Yes, that's true. I wrapped this function in my custom base controller. Maybe it would be better if symphony can offer this shortcut in the BaseController. I think it's helpful for a lot users. |
Removing About this proposal: #11051 (comment) I think it's very interesting. I had a conversation about this thread with some trainees a few weeks ago - asking them (new users) about the different options. And one actually said that it would be great if these "shortcuts" were explicitly configured somewhere (even if you get that configuration by default with the SE). So personally, I'm interested in exploring that option as well. And yes, Twig already supports this with its namespace functionality (code blocks shown above). But I think one idea of this thread is to make a resource syntax that works everywhere. We don't necessarily need this, but a unifying syntax across all resources is one goal. (Also @empire the answer to your question is here: http://symfony.com/doc/current/cookbook/templating/namespaced_paths.html#multiple-paths-per-namespace :) ) There are some details that need to be worked out with the explicit Cheers! |
Another point against the removal of |
@weaverryan Thanks Ryan ;) |
@weaverryan If I understand your comment:
Do you mean that all bundles would have to explicitly define a namespace for their resources? Ie.
If so, then I disagree. It's an easy convention to remember, and it's not confusing. If it's as it is currently, then ignore my complaint :) |
👍 @kingcrunch Also, an |
magic 👎 @kingcrunch 👍 👍 👍 |
@cjunge-work I really mean that we need to keep backwards-compatibility somehow. So if we introduced the syntax, then we'd probably need to continue to make I do like this resources proposal by @kingcrunch, but does it solve our goals?
And then use: return $this->render('@MyCoolBundle_views/Default/index.html.twig'); I'm not clear yet how I would use this feature to make rendering my templates make more sense, without something kind of ugly like |
When will this RFC close? |
Also imo it makes sense to disallow setting own resource names ending in |
@weaverryan @kingcrunch
If some day you want to change your base you just need to change the mapping. I think is important to start with bundle name because we can have it in src or in vendor |
👍 on 4 |
@felds This won't close at any specific time. In fact, if we can't find a better solution we agree on, we won't do anything :). @kingcrunch I don't think we can map @ogimenezb How would your syntax end up looking then? |
@weaverryan yes, like 4.
|
What is the use-case for the custom mappings? Aren't we just going to end up replacing However, I am generally supportive of increasing the transparency around the generation of these mappings. |
@ryancastle The use case is, that you can refer to unbundled resources, at least was my intention, when I wrote it 😄 resources:
# for example @bootstrap:js/affix.js
# https://github.com/twbs/bootstrap/blob/master/js/affix.js
bootstrap: %kernel.root_dir%/../vendor/twbs/bootstrap
# Note, that I did _not_ include the js/ folder in the mapping
# Because I want all resources from this component (css, maybe less, ...) (This example doesn't make any assumptions about the syntax. It's just to clarify the use-case of custom resource path mappings) I'ven chosen bootstrap as example, because it indeed as a Imo it is pretty ugly to use custom mappings to point to a folder within a bundle folder. Following convention-over-configuration every bundled resource should be below |
Interesting discussion. I am not as seasonned as most contributors here, but I have been a sf2 user for 3 years and sf1 before that, so I'll throw in my 2 cents. First, I don't see much problem with the existing convention. Now, if you guys are looking at changing that, and since this issue is related to directory structure, I'd like to rebound on @weaverryan 's questionning of the position of the views directory. As a matter of fact, one of the main things that has been tickling me in sf2 (and the devs I introduce to sf2) is the treatement of views and routing in the directory structure. When I learned symfony2, 3 years ago, I read that everything starts with 3 fundamental things: a route, a controller and a template. Don't take my word for it, here is Ryan's ( http://symfony.com/doc/current/book/page_creation.html ). Indeed, routes, controllers and views are all you need to build a simple page. As such, it seems they should be treated as first class citizens. Strangely when you look at directory structure, views (lowercase) are under Resources. When I think of Resources, it doesn't strike me as a "core component". In most people's mind, it's more likely to be associated with something external. Routes are hidden even deeper, in Resources/config. I suppose you could see a route as a configuration, but really ? I prefer to see a routing as an independant component, separate from bundle configuration. Obviously the current directory structure separates php from the other stuff. is that important ? Not to me. The views and routing are more essential than all sorts of directories you might find at the root ( Event, Helper, DataFixtures, Translation, etc.). Long story short, I would like to throw in the blasphemous idea of moving Views (capitalized) and Routing to the bundle root. Which, back to the current discussion, would make things nice and clear
or even
fitting directory structure. |
I still very much agree with @kingcrunch and would love if we could find a solution based on it. It provides the perfect balance as an explicit, concise, configurable and customizable solution (imho). |
As the creator of Puli, I'd like to weigh in here as I was designing Puli precisely to solve the problems discussed here. I think that Puli would be a very nice and clean solution to most of the points I read here. Basically, Puli maps "virtual paths" to real paths in the file system, for example:
With this mapping, you can easily refer to files in the
As a simple rule, you can specify that Additionally, Puli supports protocols to - for example - let you use full file system paths where you need them (similar to the Java examples above):
Note that PHP's stream wrappers do not support URIs with less than two slashes, so URIs like Last but not least, you can easily override individual files in Puli, for example:
I think this very simple architecture is very powerful and at the same time simple to understand. Being based on filesystem paths, relative paths are supported. For example, the following is currently not possible in Twig:
Puli supports such a relative paths, and even paths like My 2 cents. :) |
Closing it because we'll never reach an agreement. It's better to leave things as they are: Symfony supports several formats, they all work great and you can freely choose the one you prefer. |
fixes j-guyon#87, j-guyon#81 details symfony/symfony#11051
fixes j-guyon#87, j-guyon#81 details symfony/symfony#11051
(this issue is part of the "DX" ("Developer eXperience") initiative introduced by Symfony project)
On the symfony-docs repository there is a very long discussion about the new template naming syntax.
In short, some people think that the old syntax has inconsistencies in cases like the following:
@AcmeBlogBundle/Resources/views/Default/common/template4.html.twig
AcmeBlogBundle : Default : common / template4.html.twig
AcmeBlogBundle : Default / common : template4.html.twig
Using the new namespaced Twig syntax, the template name would always be:
@AcmeBlog/Default/common/template4.html.twig
Removing the
Resources/views/
part is very common and easy to understand. But removing theBundle
suffix is really strange and inconsistent with the rest of Symfony.This problem is introduced in lines 136-138 of TwigBundle/DependencyInjection/TwigExtension.php file.
Summarized Proposals
Deprecate the current behavior (0) and choose one of the following to implement and recommend:
AcmeBlogBundle:Default:index.html.twig
@AcmeBlogBundle/Default/index.html.twig
Resources/views
@AcmeBlogBundle:Default/index.html.twig
Resources/views
AcmeBlogBundle:Default/index.html.twig
Resources/views
@AcmeBlogBundle:views/Default/index.html.twig
Resources
, could also be used consistent with routing importsAcmeBlogBundle:views/Default/index.html.twig
Resources
view@AcmeDemoBundle/Default/index.html.twig
public@
,config@
that could be used elsewhereThe text was updated successfully, but these errors were encountered: