[Templating] Added ability to set a specific version of the asset#6092
Closed
hason wants to merge 2 commits intosymfony:masterfrom
Closed
[Templating] Added ability to set a specific version of the asset#6092hason wants to merge 2 commits intosymfony:masterfrom
hason wants to merge 2 commits intosymfony:masterfrom
Conversation
Contributor
hason
commented
Nov 22, 2012
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | |
| License | MIT |
| Doc PR |
Contributor
Author
There was a problem hiding this comment.
If you want to disable generating versioned url.
Member
|
@hason: What is your use case? |
Contributor
Author
|
First use case: I want to generate a path to the directory (eg. themes for jsTree) $.jstree._themes = {{ asset("PATH/TO/FOLDER/", null, false)|json_encode }};Second use case: I want to set a specific version of the asset (eg. regenerate every day): {{ asset("path/to/asset", null, "now"|date("mdY")) }} |
Member
|
Ok, you've just described what the change does, and I understood that. But why would you want to set a specific version for the assets? I cannot think of a real-world use case for that. |
Contributor
Author
|
Ok, how we make the first real use case (a path to the directory without var AMCHARTS_PATH_TO_IMAGES = {{ asset("@amcharts/amcharts/amcharts/images/", null, false)|json_encode|raw }};And yes I want rather local shutdown versioning. |
Member
|
closing in favor of #10593 |
fabpot
added a commit
that referenced
this pull request
Mar 31, 2014
…f the asset (romainneutron) This PR was merged into the 2.5-dev branch. Discussion ---------- [Templating] Added ability to set a specific version of the asset | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT | Doc PR | https://github.com/symfony/symfony-docs/pull/3742/files This PR replaces #6092 Commits ------- 1642094 [Templating] Update changelog 6fce503 [Templating] Added ability to set a specific version of the asset
fabpot
added a commit
that referenced
this pull request
Feb 10, 2015
This PR was merged into the 2.7 branch. Discussion ---------- [Asset] added the component | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #10973, #11748, #11876, #4883, #12474 | License | MIT | Doc PR | not yet TODO: - [ ] submit documentation PR The current Asset sub-namespace in Templating has several (major) problems: * It does not cover all use cases (see #10973 and #4883 for some example) * It has some design issues (relies on the Request instance and so requires the request scope, very coupled with the PHP templating sub-system, see #11748 and #11876) To decouple this feature and make it reusable in Silex for instance, and to fix the design issues and make it more extensible, I've decided to extract and rework the features provided into a new Asset component. Basically, this component allows the developer to easily manage asset URLs: versioning, paths, and hosts. Both the new and the old asset management features are kept in this PR to avoid breaking BC; the old system is of course deprecated and automatically converted to the new one. Even if the features are quite similar, and besides the flexilibity of the new system, here are some differences: * `PathPackage` always prepend the path (even if the given path starts with `/`). * Usage is stricter (for instance, `PathPackage` requires a basePath to be passed and `UrlPackage` requires that at least on URL is passed). * In the configuration, named packages inherits from the version and version format of the default package by default. * It is not possible to override the version when asking for a URL (instead, you can define your own version strategy implementation -- the use cases explained in #6092 are easily implemented this way). * It's not possible to generate absolute URLs (see #13264 for a better alternative using composition; so using `absolute_url(asset_path('me.png')) should work)`. #10973 was about adding shortcuts for bundles, which is a good idea; but given that you rarely reference built-in or third-party bundle assets and because we now have a one-bundle default approach named AppBundle, the same can be achieved with just a simple piece of configuration with the new assets feature: ```yml framework: assets: packages: app: base_path: /bundles/app/ img: base_path: /bundles/app/images/ ``` Then: ```jinja {{ asset('images/me.png', 'app') }} # /bundles/app/images/me.png {{ asset('me.png', 'img') }} # /bundles/app/images/me.png ``` #12474 discussed the possibility to add a version for absolute URL. It's not possible to do that in a generic way as the version strategy involves both the version and the path, which obviously cannot work when the path is an absolute URL already. Instead, one should use the `asset_version` Twig function to add the version manually. Commits ------- 0750d02 removed usage of the deprecated forms of asset() in the core framework f74a1f2 renamed asset_path() to asset() and added a BC layer 4d0adea [Asset] added a NullContext class d33c41d [Asset] added the component
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.