When I output my ImageOptimize field in the template, my images are not showing up. If you inspect the image url, it's missing a folder name I'm specifying as part of the url in my multi-environment setup and volume config.
If I manually change the image url in the browser tools to include the missing folder, the image shows up. Other images are rendered fine when using the standard asset field code so I'm not sure what could be wrong.
Things to note:
- I am using Andrew's multi-environment setup.
- I have two separate folders in my web root folder:
- In the folder
assets/
, I'm serving my template assets like css, images, and fonts. - In the folder
content/
, I'm serving the files uploaded to the volumes I have setup in Craft - images, logos, documents etc.
- In the folder
My environment variables:
'BASE_URL' => $protocol . $httpHost . '/',
'BASE_PATH' => realpath(dirname(__FILE__)) . '/web/content/',
My aliases (set for all environments):
'aliases' => [
'@basePath' => getenv('CRAFTENV_BASE_PATH'),
'@baseUrl' => getenv('CRAFTENV_BASE_URL'),
],
My volume config:
'*' => [
'images' => [
'path' => '@basePath/images',
'url' => '@baseUrl/content/images',
],
],
My ImageOptimize snippet:
<img src="{{ optimizedImages.src() }}"
srcset="{{ optimizedImages.srcset() }}"
sizes="100vw" />
The image path being used on the frontend (note the absence of the content/
folder):
<img src="https://franklin.test/images/_1920x1080_crop_center-center_82_line/national-formulation-centre.jpg" srcset="https://franklin.test/images/_1920x1080_crop_center-center_82_line/national-formulation-centre.jpg 1920w">