Whatβs the correct way to reference an image asset in Blade?
Is that even documented? If it is, I have yet to figure out where to find it.
Thanks!
Whatβs the correct way to reference an image asset in Blade?
Is that even documented? If it is, I have yet to figure out where to find it.
Thanks!
Try {{ asset('...') }}
or {{ Vite::asset('...') }}
instead of the directive. The latter should work for sure, but I think the first one does too.
@Log1x thank you for your suggestion.
It seems like, for some reason, the manifest.json
file is not getting published. When using {{ asset('images/cover-image.avif') }}
, Iβm getting the following exception:
Fatal error: Uncaught Roots\Acorn\Assets\Exceptions\ManifestNotFoundException
Which is referring to The asset manifest [/Users/.../Local Sites/tdh/app/public/wp-content/themes/tdh/public/manifest.json] cannot be found.
When calling the {{ Vite::asset('images/cover-image.avif') }}
static method, Iβm getting a 404 Not Found exception, referring to
GET
http://[::1]:5173/app/themes/sage/public/build/images/cover-image.avif
Any idea of whatβs causing this?
I also ran npm run build
, which created a build/assets
directory located inside public
. And I can see my cover-image-DSsIqvXq.avif
in there, but no way to access it.
In your public/build
directory, do you see a manifest after you run the build command?
If yes, youβll need to reference the image the same way itβs listed in the manifest. You probably need resources
added to the path. eg. resources/images/cover-image.avif
@csorrentino the structure of my public/build
directory is:
.
βββ build
β βββ assets
β β βββ app-D-TnrBR6.css
β β βββ app-l0sNRNKZ.js
β β βββ editor-CfU4GbSP.js
β β βββ editor-jAUPbkXe.css
β β βββ cover-image-DSsIqvXq.avif
β β βββ tdh-logo-vector-DQ0grIrs.svg
β β βββ theme.json
β βββ editor.deps.json
β βββ manifest.json
βββ hot
So yes, the manifest.json file is in there. As per your advice, I prepended resources/
to my assetβs path, i.e.
{{ Vite::asset('resources/images/cover-image.avif') }}
and that suddenly made it work.
I am so grateful for your help.