Skip to content

Commit 0dbb635

Browse files
authored
Path package in context aware
How to reproduce : - Application has a base url (/some-base-url) - Using "PathPackage" - Using RequestStackContext (3rd parameter), - getUrl of asset with absolute path. Result : Both "base url" of application and "base path" of PathPackage are ignored. Example : Application base url : /some-prefix $package = new PathPackage('/static/', new StaticVersionStrategy('v1.2'), new RequestStackContext($requestStack)); echo $package->getUrl("/img.png"); // /img.png?v1.2 Check merged PR #8574. NB : Maybe there a conception problem in Asset component. I my opinion only "base path" should be ignored but "base url" should always be used to prefix the generated asset path.
1 parent b501c41 commit 0dbb635

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

components/asset.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,13 @@ class can take into account the context of the current request::
204204
new StaticVersionStrategy('v1'),
205205
new RequestStackContext($requestStack)
206206
);
207-
208-
echo $package->getUrl('/logo.png');
207+
208+
echo $package->getUrl('logo.png');
209209
// result: /somewhere/static/images/logo.png?v1
210+
211+
// Both "base path" and "base url" are ignored when using absolute path for asset
212+
echo $package->getUrl('/logo.png');
213+
// result: /logo.png?v1
210214

211215
Now that the request context is set, the ``PathPackage`` will prepend the
212216
current request base URL. So, for example, if your entire site is hosted under

0 commit comments

Comments
 (0)