Getting an image as an object for an image in the assets directory

Highlighted
Shopify Partner
1 0 1

Hello!

I want to use a snippet `bgset.liquid` that came with my theme for generating a list of different image sizes for an image. To do this I need an images object. This image is being hardcoded into the page template. I can do this if I upload the image on the site;

{% assign imgObj = images['test-large.png'] %}

I was wondering if it's possible to do this with an image that lives in the `/assets` directory. Say something like;

{% assign imgObj = images['assets/test-large.png'] %}
1 Like
Highlighted
Shopify Partner
1366 24 246

Hey,

Not sure what you want to do in there but you can access an asset image with the asset_img_url filter.

Please have a look at the docs: https://help.shopify.com/en/themes/liquid/filters/url-filters#asset_img_url

https://sections.design tips, tricks & Shopify sections
0 Likes
Highlighted
Shopify Partner
5 0 1

I'm trying to do the same thing, and can't even get that snippet to work for pulling an asset from the Files section as an image object.

He's trying to references images in the assets/ folder as image objects so that we can access object properties and run useful performance related functions like the responsive-bg-image.liquid snippet.

There is no reference or documentation I can find on this whatsoever and it's so weird - the majority of images on my site are not product images so why isn't there a way to reference static assets as objects?

1 Like
Highlighted
New Member
1 0 1

Not sure if this is still useful to you, but for anyone looking. The answer is in this post. I haven't found this documented anywhere.

You can use the global images object (docs) with the name of the image from your Files upload. That should be enough to start using it as an image object:

{{ images['my-file-name.jpg'].aspect_ratio }}

 

1 Like