Answers.Body: <p>I would add the brand category field to the assets field set. This way you can add brands to images and use <code>.relatedTo</code> to find them.</p>
  
  <pre><code>&lt;ul&gt;
    {% for category in craft.categories.group( 'brands' ) %}
      // This will give you the first image that relates to the category, you could use .find() to get all images and then loop through them.
      {% set image = craft.assets.relatedTo( category ).first() %}
  
      &lt;li&gt;
        &lt;a href="{{ category.url }}"&gt;
          {% if image|length %}
            &lt;img src="{{ image.url }}" /&gt;
          {% else %}
            &lt;img src="http://placehold.it/400x300" /&gt;
          {% endif %}
        &lt;/a&gt;
      &lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-21T09:05:26.017Z
Answers.Text: Perfect. Got what I needed and learned something new. Thank you Luke!
Answers.UserDisplayName: Kitsune
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-22T09:36:35.550Z
Answers.Text: @kitsune what if you'd just add an asset field "logo" to the categories? That makes it possible to use the more convenient syntax `myCategory.logo.first()` to get a category's brand logo. Makes more sense from the data entry aswell, add logo, address, etc. to the brand category.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-22T10:37:40.153Z
Answers.Text: I'd implement my way if there are many images related to a category but go with carlcs way if you only need a single image to be associated with a category.
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-21T08:53:36.327Z
Answers.LastActivityDate: 2016-05-21T09:22:42.077Z
Answers.LastEditDate: 2016-05-21T09:22:42.077Z
Answers.UserDisplayName: Luke Pearce
Body: <p>What would be the best approach to have a list of categories (brands in my case.) and if an asset (image) exists that matches that brand name show that asset or instead show a placeholder image.</p>
  
  <pre><code>&lt;ul&gt;
  {% for category in craft.categories.group('brands') %}
      &lt;li&gt;
          &lt;a href="{{ category.url }}"&gt;
              &lt;img src="{{ .. }}" /&gt;
          &lt;/a&gt;
      &lt;/li&gt;
  {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-21T08:28:10.557Z
Comments.Text: So with something along the lines of;
  
  `{% for image in craft.assets.kind('brands') %}
       <li>
          <a href="{{ category.url }}">
              <img src="{{ image.getUrl() }}" />
          </a>
      </li></li>
  {% endfor %}`
  
  But with an if statement there too, if it's exist use it, else a placeholder url for the src.
Comments.UserDisplayName: Kitsune
Tags: <assets><categories>
Title: Find matching asset (image) for category
ThreadText: # Find matching asset (image) for category
  
  (Asked by: username_0 on 2016-05-21)
  
  What would be the best approach to have a list of categories (brands in my case.) and if an asset (image) exists that matches that brand name show that asset or instead show a placeholder image.
  
  ```
  <ul>
  {% for category in craft.categories.group('brands') %}
      <li>
          <a href="{{ category.url }}">
              <img src="{{ .. }}" />
          </a>
      </li>
  {% endfor %}
  </ul>
  
  ```
  
  **Tags:** assets, categories
  
  > **Comments:**
  > **username_0**: So with something along the lines of;  `{% for image in craft.assets.kind('brands') %}      <li>         <a href="{{ category.url }}">             <img src="{{ image.getUrl() }}" />         </a>     </li></li> {% endfor %}`  But with an if statement there too, if it's exist use it, else a placeholder url for the src.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-21. Score: 4 | Accepted answer
  
  I would add the brand category field to the assets field set. This way you can add brands to images and use `.relatedTo` to find them.
  
  ```
  <ul>
    {% for category in craft.categories.group( 'brands' ) %}
      // This will give you the first image that relates to the category, you could use .find() to get all images and then loop through them.
      {% set image = craft.assets.relatedTo( category ).first() %}
  
      <li>
        <a href="{{ category.url }}">
          {% if image|length %}
            <img src="{{ image.url }}" />
          {% else %}
            <img src="http://placehold.it/400x300" />
          {% endif %}
        </a>
      </li>
    {% endfor %}
  </ul>
  
  ```
  
  > **Comments:**
  > **username_0**: Perfect. Got what I needed and learned something new. Thank you username_1!  
  > **username_2**: @username_0 what if you'd just add an asset field "logo" to the categories? That makes it possible to use the more convenient syntax `myCategory.logo.first()` to get a category's brand logo. Makes more sense from the data entry aswell, add logo, address, etc. to the brand category.  
  > **username_1**: I'd implement my way if there are many images related to a category but go with username_2 way if you only need a single image to be associated with a category.  
  
  ---
  
  