<p>Ok first thing take the s off relatedProduct because each loop is over <strong>one</strong> relatedProduct ;) - then you can do something like this:</p>

<pre><code>{% for relatedProduct in product.relatedAccessories %}
   {{ relatedProduct.title }} - {{ relatedProduct.accessoryDescription }}
   Url: {{ relatedProduct.yourAssetHandle.first().url }}
{% endfor %}
</code></pre>

<p>You should probably protect that by first checking <code>{% if relatedProduct.yourAssetHandle.first()|length %}</code> unless you can be completely certain you will have an asset (required field for example).</p>

CC BY-SA 3.0
2016-03-04T15:43:34.333Z
Perfect! That solved it. And a few other things for me to boot.
Wonko
CC BY-SA 3.0
2016-03-04T21:36:21.877Z
Glad to hear it - please accept it as an answer as I am shallow enough to desire points ;)
Jeremy Daalder
CC BY-SA 3.0
2016-03-04T05:32:35.250Z
2016-03-04T05:32:35.250Z
Jeremy Daalder
<p>Folks:</p>

<p>I'm using CraftCommerce. I have a main product and several accessories related to that product. Accessories have a title, description, price, and image.</p>

<p>Now, I have no problem pulling the title and description for the related accessories using this:</p>

<pre><code>    {% for relatedProducts in product.relatedAccessories %}
       {{ relatedProducts.title }} - {{ relatedProducts.accessoryDescription }}
    {% endfor %}
</code></pre>

<p>Where I've got a problem is pulling the related image. If I use <code>{{ asset.getUrl }}</code> it pulls the first image from the main product entry rather than the image in the related entry. I have tried <a href="https://craftcms.stackexchange.com/questions/4220/get-image-from-related-entries-asset-field">Get image from related entries asset field</a> and <a href="https://craftcms.stackexchange.com/questions/630/how-do-i-pull-related-entries-and-assets/640#640">How do I pull related entries and assets</a>? without success.</p>

<p>Any assistance would be great.</p>

<relations><plugin-craftcommerce>
Displaying image from related CraftCommerce entry
# Displaying image from related CraftCommerce entry

(Asked by: username_0 on 2016-03-03)

Folks:
I'm using CraftCommerce. I have a main product and several accessories related to that product. Accessories have a title, description, price, and image.
Now, I have no problem pulling the title and description for the related accessories using this:
    {% for relatedProducts in product.relatedAccessories %}
       {{ relatedProducts.title }} - {{ relatedProducts.accessoryDescription }}
    {% endfor %}

Where I've got a problem is pulling the related image. If I use {{ asset.getUrl }} it pulls the first image from the main product entry rather than the image in the related entry. I have tried Get image from related entries asset field and How do I pull related entries and assets? without success.
Any assistance would be great.

**Tags:** relations, plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2016-03-04. Score: 2 | Accepted answer

Ok first thing take the s off relatedProduct because each loop is over one relatedProduct ;) - then you can do something like this:
{% for relatedProduct in product.relatedAccessories %}
   {{ relatedProduct.title }} - {{ relatedProduct.accessoryDescription }}
   Url: {{ relatedProduct.yourAssetHandle.first().url }}
{% endfor %}

You should probably protect that by first checking {% if relatedProduct.yourAssetHandle.first()|length %} unless you can be completely certain you will have an asset (required field for example).

> **Comments:**
> **username_0**: Perfect! That solved it. And a few other things for me to boot.  
> **username_1**: Glad to hear it - please accept it as an answer as I am shallow enough to desire points ;)  

---

