Answers.Body: <p>You probably have to query a new ElementCriteriaModel for each asset in your loop and use the <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="noreferrer"><code>relatedTo</code></a> parameter to filter the relevant "content" entries.</p>
  
  <p>You could use the <code>targetElement</code> property with the <code>relatedTo</code> parameter to be more spezific on that relation. But you should be fine using the <code>element</code> property or the short syntax <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="noreferrer"><code>relatedTo(element)</code></a>, if you don't do any (reverse) relations (e.g. with an entries field as an <a href="http://buildwithcraft.com/docs/assets#asset-meta-fields" rel="noreferrer">asset meta field</a>).</p>
  
  <p>Tested this on an install with 400 images and yes, you want to wrap it in <code>cache</code> tags!</p>
  
  <pre><code>{% set content = craft.entries.section('content').find() %}
  {% set usedFotos = craft.assets.relatedTo(content).order('filename').find() %}
  
  {# Loop throught the array of assets #}
  {% for usedFoto in usedFotos %}
  
      &lt;h2&gt;{{ usedFoto.filename }}&lt;/h2&gt;
      &lt;ul&gt;
  
          {# Loop throught entries related to this asset #}
          {% for entry in craft.entries.relatedTo(usedFoto).order('title') %}
              &lt;li&gt;{{ entry.title }}&lt;/li&gt;
          {% endfor %}
  
      &lt;/ul&gt;
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-19T11:23:30.667Z
Answers.LastActivityDate: 2014-08-19T11:32:23.077Z
Answers.LastEditDate: 2014-08-19T11:32:23.077Z
Answers.UserDisplayName: carlcs
Body: <p>Given a list of assets, for each asset, how do I display a list of entries that relate to this asset? So, for instance, if asset A is selected as asset in entries 1 and 2, I want a list to be displayed like this:</p>
  
  <ul>
  <li>Asset A:
  <ul>
  <li>Used in entry 1</li>
  <li>Used in entry 2</li>
  </ul></li>
  <li>Asset B:
  <ul>
  <li>Used in ... etc.</li>
  </ul></li>
  </ul>
  
  <p>With this ...</p>
  
  <pre><code>{% set content = craft.entries.section('content').find() %}
  {% set usedFotos = craft.assets.relatedTo(content).find() | group('id') %}
  </code></pre>
  
  <p>... I can see if certain assets are used, but now I want to see what entr(y/ies) they belong to.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T16:13:24.347Z
Comments.Text: Paul, did the answer I provided help you with your problem?
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T16:16:18.327Z
Comments.Text: Didn't have a chance to try yet, will do tonight. Was hoping for a 'one-query solution' ;)
Comments.UserDisplayName: Paul
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T16:21:48.673Z
Comments.Text: Yeah I also hoped to find a solution with less DB queries, but I don't think it's possible.
Comments.UserDisplayName: carlcs
Tags: <entries><assets><relations><assetfilemodel>
Title: How do I display a list of assets with the entries they are related to?
ThreadText: # How do I display a list of assets with the entries they are related to?
  
  (Asked by: username_0 on 2014-08-19)
  
  Given a list of assets, for each asset, how do I display a list of entries that relate to this asset? So, for instance, if asset A is selected as asset in entries 1 and 2, I want a list to be displayed like this:
  
  * Asset A:
    + Used in entry 1
    + Used in entry 2
  * Asset B:
    + Used in ... etc.
  
  With this ...
  
  ```
  {% set content = craft.entries.section('content').find() %}
  {% set usedFotos = craft.assets.relatedTo(content).find() | group('id') %}
  
  ```
  
  ... I can see if certain assets are used, but now I want to see what entr(y/ies) they belong to.
  
  **Tags:** entries, assets, relations, assetfilemodel
  
  > **Comments:**
  > **username_1**: username_0, did the answer I provided help you with your problem?  
  > **username_0**: Didn't have a chance to try yet, will do tonight. Was hoping for a 'one-query solution' ;)  
  > **username_1**: Yeah I also hoped to find a solution with less DB queries, but I don't think it's possible.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-08-19. Score: 5 | Accepted answer
  
  You probably have to query a new ElementCriteriaModel for each asset in your loop and use the [`relatedTo`](http://buildwithcraft.com/docs/relations#the-relatedTo-param) parameter to filter the relevant "content" entries.
  
  You could use the `targetElement` property with the `relatedTo` parameter to be more spezific on that relation. But you should be fine using the `element` property or the short syntax [`relatedTo(element)`](http://buildwithcraft.com/docs/relations#the-relatedTo-param), if you don't do any (reverse) relations (e.g. with an entries field as an [asset meta field](http://buildwithcraft.com/docs/assets#asset-meta-fields)).
  
  Tested this on an install with 400 images and yes, you want to wrap it in `cache` tags!
  
  ```
  {% set content = craft.entries.section('content').find() %}
  {% set usedFotos = craft.assets.relatedTo(content).order('filename').find() %}
  
  {# Loop throught the array of assets #}
  {% for usedFoto in usedFotos %}
  
      <h2>{{ usedFoto.filename }}</h2>
      <ul>
  
          {# Loop throught entries related to this asset #}
          {% for entry in craft.entries.relatedTo(usedFoto).order('title') %}
              <li>{{ entry.title }}</li>
          {% endfor %}
  
      </ul>
  
  {% endfor %}
  
  ```
  
  
  ---
  
  