Skip to content

Commit a29765d

Browse files
authored
Asset Component and absolute paths
How alsolute paths are handeled in Package and PathPackage.
1 parent 95a79fd commit a29765d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/asset.rst

Lines changed: 17 additions & 0 deletions
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
.........................
@@ -170,6 +183,10 @@ that path over and over again::
170183

171184
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)