Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use new product_image templatetag in templates

Artur Smęta060d4fb4ab2
diff --git a/templates/category/_items.html b/templates/category/_items.html
index 8b2519fdfe..8f5d8b041c 100644
--- a/templates/category/_items.html
+++ b/templates/category/_items.html
@@ -2,17 +2,20 @@
{% load staticfiles %}
{% load price_range from price_ranges %}
{% load discounted_price_range price_difference from discount %}
+{% load product_image from product_images %}
{% for product in products %}
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3" itemscope itemtype="https://schema.org/Product">
<div class="panel panel-default text-center">
<div class="panel-body">
<a itemprop="url" href="{{ product.get_absolute_url }}">
- {% if product.images.first %}
- <img itemprop="image" class="img-responsive" src="{{ product.images.first.image.crop.400x400 }}" alt="">
- {% else %}
- <img src="{% static 'images/product-image-placeholder.png' %}" alt="" class="img-responsive">
- {% endif %}
+ {% with product_image=product.get_first_image %}
+ {% if product_image %}
+ <img itemprop="image" class="img-responsive" src="{% product_image product_image method="crop" size="400x400" %}" alt="">
+ {% else %}
+ <img src="{% static 'images/product-image-placeholder.png' %}" alt="" class="img-responsive">
+ {% endif %}
+ {% endwith %}
<span class="product-list-item-name" itemprop="name" title="{{ product }}">{{ product }}</span>
</a>
</div>
diff --git a/templates/product/details.html b/templates/product/details.html
index 0cd297354b..b7b714e476 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -5,6 +5,7 @@
{% load gross from prices_i18n %}
{% load markdown from markdown %}
{% load price_range from price_ranges %}
+{% load product_image from product_images %}
{% load static from staticfiles %}
{% block title %}{{ product }} — {{ block.super }}{% endblock %}
@@ -55,8 +56,8 @@
<hr>
<div class="visible-xs">
- {% if product.images.first %}
- <img class="img-responsive" src="{{ product.images.first.image.crop.680x680 }}" alt="">
+ {% if product_images %}
+ <img class="img-responsive" src="{% product_image product_images.0.image method="crop" size="680x680" %}" alt="">
{% else %}
<img src="{% static 'images/product-image-placeholder.png' %}" alt="" class="img-responsive">
{% endif %}
@@ -89,14 +90,14 @@
</div>
- {% with images=product.images.all %}
+ {% with images=product_images %}
<div class="col-sm-6 col-sm-pull-6">
<div id="product-carousel" class="carousel slide panel panel-default hidden-xs" data-ride="carousel">
<div class="carousel-inner">
{% for image in images %}
<div class="item{% if forloop.first %} active{% endif %}">
<a href="#" data-toggle="modal" data-target="#modal-{{ forloop.counter }}">
- <img class="img-responsive" src="{{ image.image.crop.750x750 }}" alt="">
+ <img class="img-responsive" src="{% product_image image.image method="crop" size="750x750" %}" alt="">
</a>
</div>
{% empty %}
@@ -128,7 +129,7 @@
<div class="product-gallery row">
{% for image in images %}
<a href="{{ image.image.url }}" target="_blank" class="product-gallery-item col-xs-6 col-md-3">
- <img class="thumbnail img-responsive" src="{{ image.image.crop.280x280 }}" alt="">
+ <img class="thumbnail img-responsive" src="{% product_image image.image method="crop" size="280x280" %}" alt="">
</a>
{% endfor %}
</div>