Answers.Body: <p><code>product.gallery</code> returns an <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a>, which you can think of as a list of elements. <code>product.gallery.first()</code> will return the <a href="https://craftcms.com/docs/templating/elementcriteriamodel#first" rel="nofollow">first</a> element in this list.</p>
  
  <p>What you want is to loop over all the elements:</p>
  
  <pre><code>{% for asset in product.gallery %}
    &lt;img src="{{ asset.url }}"&gt;
  {% endfor %}
  </code></pre>
  
  <p>(Note that this will work if there are no elements in the list (because the for loop will never be entered). One thing you should avoid doing is <code>product.gallery.first().url</code>, because it is <strong>never</strong> possible to be certain without checking that there <em>is</em> a first element in the list.)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-18T00:44:50.703Z
Answers.LastActivityDate: 2016-07-18T01:15:52.930Z
Answers.LastEditDate: 2016-07-18T01:15:52.930Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>I am trying to loop through an assets field called <code>gallery</code> on entries in a commerce <code>products</code> channel.</p>
  
  <p>This field can have multiple images in it. I can get this to work on a channel listing page <code>domain.com/shop/</code> but can't get this to work on the entry detail page <code>domain.com/shop/products/detail/</code>.</p>
  
  <p>Any help is appreciated.</p>
  
  <pre><code>{% for asset in product.gallery.first() %}
      &lt;img src="{{ asset.url }}"&gt;
  {% endfor %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-18T01:14:53.227Z
Comments.Text: I edited your question just to clarify some of the naming - the `gallery` field is on entries in a commerce products channel.
Comments.UserDisplayName: Jeremy Daalder
Tags: <assets><plugin-craftcommerce><loop>
Title: Loop through assets field on detail/product page
ThreadText: # Loop through assets field on detail/product page
  
  (Asked by: username_0 on 2016-07-16)
  
  I am trying to loop through an assets field called `gallery` on entries in a commerce `products` channel.
  
  This field can have multiple images in it. I can get this to work on a channel listing page `domain.com/shop/` but can't get this to work on the entry detail page `domain.com/shop/products/detail/`.
  
  Any help is appreciated.
  
  ```
  {% for asset in product.gallery.first() %}
      <img src="{{ asset.url }}">
  {% endfor %}
  
  ```
  
  **Tags:** assets, plugin-craftcommerce, loop
  
  > **Comments:**
  > **username_1**: I edited your question just to clarify some of the naming - the `gallery` field is on entries in a commerce products channel.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-07-18. Score: 3
  
  `product.gallery` returns an [ElementCriteriaModel](https://craftcms.com/docs/templating/elementcriteriamodel), which you can think of as a list of elements. `product.gallery.first()` will return the [first](https://craftcms.com/docs/templating/elementcriteriamodel#first) element in this list.
  
  What you want is to loop over all the elements:
  
  ```
  {% for asset in product.gallery %}
    <img src="{{ asset.url }}">
  {% endfor %}
  
  ```
  
  (Note that this will work if there are no elements in the list (because the for loop will never be entered). One thing you should avoid doing is `product.gallery.first().url`, because it is **never** possible to be certain without checking that there *is* a first element in the list.)
  
  
  ---
  
  