From 95a79fde861b902cfa851b09d42a6ce7fec4d814 Mon Sep 17 00:00:00 2001 From: takman1 Date: Wed, 1 Nov 2017 13:56:35 +0100 Subject: [PATCH 1/2] Grouped assets example When absolute path is provided in getUrl(), base path is ignored. --- components/asset.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/asset.rst b/components/asset.rst index 0791d7bf84a..b368b68e01b 100644 --- a/components/asset.rst +++ b/components/asset.rst @@ -168,7 +168,7 @@ that path over and over again:: $package = new PathPackage('/static/images', new StaticVersionStrategy('v1')); - echo $package->getUrl('/logo.png'); + echo $package->getUrl('logo.png'); // result: /static/images/logo.png?v1 Request Context Aware Assets From a29765d15b41a9a65c899dcce6382a7c0606452b Mon Sep 17 00:00:00 2001 From: takman1 Date: Mon, 6 Nov 2017 00:44:41 +0100 Subject: [PATCH 2/2] Asset Component and absolute paths How alsolute paths are handeled in Package and PathPackage. --- components/asset.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/asset.rst b/components/asset.rst index b368b68e01b..da05a7c4451 100644 --- a/components/asset.rst +++ b/components/asset.rst @@ -63,8 +63,13 @@ any versioning:: $package = new Package(new EmptyVersionStrategy()); + // Absolute path echo $package->getUrl('/image.png'); // result: /image.png + + // Relative path + echo $package->getUrl('image.png'); + // result: image.png Packages implement :class:`Symfony\\Component\\Asset\\PackageInterface`, which defines the following two methods: @@ -105,8 +110,13 @@ suffix to any asset path:: $package = new Package(new StaticVersionStrategy('v1')); + // Absolute path echo $package->getUrl('/image.png'); // result: /image.png?v1 + + // Relative path + echo $package->getUrl('image.png'); + // result: image.png?v1 In case you want to modify the version format, pass a sprintf-compatible format string as the second argument of the ``StaticVersionStrategy`` constructor:: @@ -122,6 +132,9 @@ string as the second argument of the ``StaticVersionStrategy`` constructor:: echo $package->getUrl('/image.png'); // result: /v1/image.png + + echo $package->getUrl('image.png'); + // result: v1/image.png Custom Version Strategies ......................... @@ -170,6 +183,10 @@ that path over and over again:: echo $package->getUrl('logo.png'); // result: /static/images/logo.png?v1 + + // Base path is ignored when using absolute paths + echo $package->getUrl('/logo.png'); + // result: /logo.png?v1 Request Context Aware Assets ............................