Answers.Body: <p>Indigo Viking's code will achieve what you want, but if you want a simpler solution (possibly a bit more performant since there's no second <code>for</code> loop), you could do this instead:</p>
  
  <pre><code>{% set suitability = craft.categories.group('suitability').all() %}
  
  {% for category in suitability %}
      &lt;dt class="data-list__item data-list__item--title"&gt;
          {{ category.title }}
      &lt;/dt&gt;
      &lt;dd class="data-list__item data-list__item--value"&gt;
          {% if category.id in product.suitability.ids() %}
              Yes
          {% else %}
              No
          {% endif %}
      &lt;/dd&gt;
  {% endfor %}
  </code></pre>
  
  <p>The way this works is <code>product.suitability.ids()</code> returns an array of the element ids of the categories selected in your <code>suitability</code> field. Then you just check if the current category's id is in that array.</p>
  
  <p>Fast, simple, and easy!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-19T16:18:31.553Z
Answers.Text: Lovely stuff, I knew there was a really simple way of comparing items. Cheers, Jalen.
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-19T14:52:41.317Z
Answers.LastActivityDate: 2018-12-19T14:52:41.317Z
Answers.UserDisplayName: Jalen Davenport
Answers.Body: <pre><code>{% set suitability = craft.categories.group('suitability').all() %}
  
  {% for category in suitability %}
      &lt;dt class="data-list__item data-list__item--title"&gt;
          {{ category.title }}
      &lt;/dt&gt;
      &lt;dd class="data-list__item data-list__item--value"&gt;
          {% for selectedCategory in product.suitability.all() %}
              {% if selectedCategory.slug == category.slug %}
                  Yes
              {% else %}
                  No
              {% endif %}
          {% endfor %}
      &lt;/dd&gt;
  {% endfor %}
  </code></pre>
  
  <p>You'll want to loop over the list of selected categories in your product's category field (<code>product.suitability</code>) and then check the if the slug of each selected category is the same as the current slug in your main <code>for</code> loop.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-19T11:52:22.387Z
Answers.Text: This is kind of working. It's only saying "yes" by the first suitability category I've selected though.
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-19T12:43:14.477Z
Answers.Text: Missed the loop for the field itself. updating answer.
Answers.UserDisplayName: Chattervast
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-18T19:09:25.190Z
Answers.LastActivityDate: 2018-12-19T14:47:38.250Z
Answers.LastEditDate: 2018-12-19T14:47:38.250Z
Answers.UserDisplayName: Chattervast
Body: <p>I have a <code>suitability</code> category field in my product type that allows the content writer to select which categories this product is associated with.</p>
  
  <p>But my issue is that on the product page I need to show a full list of these 'suitability' categories with a "yes" or "no" next to them indicating which categories are appropriate.</p>
  
  <p>So I am getting the 'suitability' category group:</p>
  
  <pre><code>{% set suitability = craft.categories.group('suitability').all() %}
  </code></pre>
  
  <p>Then I am simply looping over this list, but I'm unsure how to format my if statement to dictate if this category needs a "yes" or a "no". I know it's probably something to do with the <code>.relatedTo()</code> parameter but I'm not quite sure on the formatting.</p>
  
  <pre><code>{% for category in suitability %}
      &lt;dt class="data-list__item data-list__item--title"&gt;{{ category.title }}&lt;/dt&gt;
      &lt;dd class="data-list__item data-list__item--value"&gt;
          {% if product.relatedTo(category) %}Yes{% else %}No{% endif %}
      &lt;/dd&gt;
  {% endfor %}
  </code></pre>
  
  <p>Thanks!</p>
  
Tags: <categories><relatedto><products>
Title: Showing a list of selected/related categories to entry
ThreadText: # Showing a list of selected/related categories to entry
  
  (Asked by: username_0 on 2018-12-18)
  
  I have a `suitability` category field in my product type that allows the content writer to select which categories this product is associated with.
  
  But my issue is that on the product page I need to show a full list of these 'suitability' categories with a "yes" or "no" next to them indicating which categories are appropriate.
  
  So I am getting the 'suitability' category group:
  
  ```
  {% set suitability = craft.categories.group('suitability').all() %}
  
  ```
  
  Then I am simply looping over this list, but I'm unsure how to format my if statement to dictate if this category needs a "yes" or a "no". I know it's probably something to do with the `.relatedTo()` parameter but I'm not quite sure on the formatting.
  
  ```
  {% for category in suitability %}
      <dt class="data-list__item data-list__item--title">{{ category.title }}</dt>
      <dd class="data-list__item data-list__item--value">
          {% if product.relatedTo(category) %}Yes{% else %}No{% endif %}
      </dd>
  {% endfor %}
  
  ```
  
  Thanks!
  
  **Tags:** categories, relatedto, products
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-12-19. Score: 3 | Accepted answer
  
  Indigo Viking's code will achieve what you want, but if you want a simpler solution (possibly a bit more performant since there's no second `for` loop), you could do this instead:
  
  ```
  {% set suitability = craft.categories.group('suitability').all() %}
  
  {% for category in suitability %}
      <dt class="data-list__item data-list__item--title">
          {{ category.title }}
      </dt>
      <dd class="data-list__item data-list__item--value">
          {% if category.id in product.suitability.ids() %}
              Yes
          {% else %}
              No
          {% endif %}
      </dd>
  {% endfor %}
  
  ```
  
  The way this works is `product.suitability.ids()` returns an array of the element ids of the categories selected in your `suitability` field. Then you just check if the current category's id is in that array.
  
  Fast, simple, and easy!
  
  > **Comments:**
  > **username_0**: Lovely stuff, I knew there was a really simple way of comparing items. Cheers, username_1.  
  
  ---
  
  ### Answer by username_2 on 2018-12-18. Score: 2
  
  ```
  {% set suitability = craft.categories.group('suitability').all() %}
  
  {% for category in suitability %}
      <dt class="data-list__item data-list__item--title">
          {{ category.title }}
      </dt>
      <dd class="data-list__item data-list__item--value">
          {% for selectedCategory in product.suitability.all() %}
              {% if selectedCategory.slug == category.slug %}
                  Yes
              {% else %}
                  No
              {% endif %}
          {% endfor %}
      </dd>
  {% endfor %}
  
  ```
  
  You'll want to loop over the list of selected categories in your product's category field (`product.suitability`) and then check the if the slug of each selected category is the same as the current slug in your main `for` loop.
  
  > **Comments:**
  > **username_0**: This is kind of working. It's only saying "yes" by the first suitability category I've selected though.  
  > **username_2**: Missed the loop for the field itself. updating answer.  
  
  ---
  
  