Skip to content

Commit 20f9e1b

Browse files
committed
feature #8574 Grouped assets example (takman1)
This PR was squashed before being merged into the 3.3 branch (closes #8574). Discussion ---------- Grouped assets example Asset > PathPackage > Grouped assets section > example When absolute path is provided in getUrl(), base path is ignored. Commits ------- a29765d Asset Component and absolute paths 95a79fd Grouped assets example
2 parents 1469c33 + a29765d commit 20f9e1b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

components/asset.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ any versioning::
6363

6464
$package = new Package(new EmptyVersionStrategy());
6565

66+
// Absolute path
6667
echo $package->getUrl('/image.png');
6768
// result: /image.png
69+
70+
// Relative path
71+
echo $package->getUrl('image.png');
72+
// result: image.png
6873

6974
Packages implement :class:`Symfony\\Component\\Asset\\PackageInterface`,
7075
which defines the following two methods:
@@ -105,8 +110,13 @@ suffix to any asset path::
105110

106111
$package = new Package(new StaticVersionStrategy('v1'));
107112

113+
// Absolute path
108114
echo $package->getUrl('/image.png');
109115
// result: /image.png?v1
116+
117+
// Relative path
118+
echo $package->getUrl('image.png');
119+
// result: image.png?v1
110120

111121
In case you want to modify the version format, pass a sprintf-compatible format
112122
string as the second argument of the ``StaticVersionStrategy`` constructor::
@@ -122,6 +132,9 @@ string as the second argument of the ``StaticVersionStrategy`` constructor::
122132

123133
echo $package->getUrl('/image.png');
124134
// result: /v1/image.png
135+
136+
echo $package->getUrl('image.png');
137+
// result: v1/image.png
125138

126139
Custom Version Strategies
127140
.........................
@@ -168,8 +181,12 @@ that path over and over again::
168181

169182
$package = new PathPackage('/static/images', new StaticVersionStrategy('v1'));
170183

171-
echo $package->getUrl('/logo.png');
184+
echo $package->getUrl('logo.png');
172185
// result: /static/images/logo.png?v1
186+
187+
// Base path is ignored when using absolute paths
188+
echo $package->getUrl('/logo.png');
189+
// result: /logo.png?v1
173190

174191
Request Context Aware Assets
175192
............................

0 commit comments

Comments
 (0)