Image

From Shopify Wiki

Jump to: navigation, search

The Liquid variable image cannot be invoked on its own. It must be invoked on a product object.

{{ product.featured_image }}
{{ product.images.first }}
{{ product.images.last }}
{{ product.images[0] }}
{{ product.images[1] }}
...
{% for image in product.images %}
  {{ image.src | product_img_url: 'compact' | img_tag: image.alt }}
{% endfor %}

Contents

image.id

The image unique ID. Image:New.gif

image.product_id

The id of the product the image belongs to. Image:New.gif

It is the same as product.id.

image.position

The position of the image among other images of the product. Image:New.gif

It is the same as the value of forloop.index when you iterate through product.images.

The fist image of the product — the one featured — has its position property set to 1.

image.src

The relative path to the product image. Image:New.gif

Example:

products/some_image.jpg

It must be used in conjunction with the product_img_url filter.

Example usage:

{% for image in product.images %}
<div class="thumbnail">
  <a href="{{ image.src | product_img_url: 'original' }}" title="{{ image.alt | escape }}">
    <img src="{{ image.src | product_img_url: 'thumb' }}" alt="{{ image.alt | escape }}" />
  </a>
</div>
{% endfor %}

Using image by itself is equivalent to using image.src.

image.alt

The description of the image. Image:New.gif

To edit that description, click on the 'ALT' link at the bottom of the product image thumbnail on your product details page in your shop admin.

If no description has been provided for an image in the shop admin, its alt property — image.alt — will output the product title.