Garfield
Garfield

Reputation: 121

Asset manifest file "manifest.json" does not exist

On a symfony5 + webpack encore application I can't access the url of an image in a controller.

Webpack is working and i access the img in twig. (with versionning) the manifest.json file exist, and I have build the assets

 $package = new Package(new JsonManifestVersionStrategy('C:\wamp64\www\svn\athena\public\build\manifest.json'));
 echo $package->getUrl('build/images/tree/families.png');

=> This is working with the direct file address of the manifest.

but with :

  $package = new Package(new JsonManifestVersionStrategy('manifest.json'));

or

$package = new Package(new JsonManifestVersionStrategy( '/build/manifest.json'));

=> I have the symfony exception : Asset manifest file "manifest.json" does not exist.

How can i make the manifest.json file address being relative ? Thanks

assets.yaml

framework:
    assets:
        json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'

Upvotes: 1

Views: 7062

Answers (1)

msg
msg

Reputation: 8181

Well, the path is supposed to be absolute...

You can inject the Packages service, that will be automatically configured:

use Symfony\Component\Asset\Packages;

public function controllerAction(Packages $packages) 
{
    $url = $packages->getUrl('build/images/tree/families.png');
}

Upvotes: 1

Related Questions