Showing a list of selected/related categories to entry 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 %}
    &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 %}


Thanks!
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 %}
    &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 %}


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!