Description
Symfony version(s) affected
6.4.1
Description
Hello community.
Since Symfony webapp-pack now requires and uses asset-mapper, I encounter an issue when it comes to retrieve the path of an asset within a bundle in dev environment.
If you have a bundle which has its own assets (in the public/ directory of the bundle to match Symfony standards) it will be imported by the assets:install
(automatically executed by the composer update
for exemple) within project public/ directory under bundles/<your-bundle>/
.
Previously, the Twig function {{ asset('bundles/<your-bundle>/desired_asset.png') }}
would get the right path as the file actually is in the project public/ directory but with asset-mapper, the path generated is is something like public/bundles//desired_asset*-**.png* which doesn't exist in dev environment unless you compile your assets which is explicitely not recommended by the asset-map:compile
command itself.
So in dev, the file is served by a specific controller BUT the issue is if you are working with the PATH_INFO ie. if your Symfony route paths are like /public/index.php/my_route, the asset will not be found because the path doesn't include index.php and so the application will generate a 404 (going to the generated URL and adding index.php after the public root part DOES WORK as exepected).
How to reproduce
- Create a bundle with any asset.
- Load the bundle and import its assets with
assets:install
command. - Refer to the asset within any template with Twig
{{ asset('bundles/<your-bundle>/<asset.ext>') }}
. - In your Symfony web application in dev environment, go to your page using PATH_INFO (http://my.app/public/index.php/route).
Possible Solution
Consider using $request->getBaseUrl()
instead of getBasePath()
in the Package/Context for this very case ?
Additional Context
No response