How to loop through category group and identify those related to entry Looping through a category group to show links to all the categories. This is an entry page and I want to highlight any categories assigned to the entry. How do I do that? I've tried this so far:

{% set cats = craft.categories.group('events').find() %}
{% for cat in cats %}
    &lt;a href="{{ cat.url }}" {% if cat.relatedTo(entry) %}class=active{% endif %}&gt;{{ cat.title }}&lt;/a&gt;
{% endfor %}
Your solution looks like it's almost there, but it would be making a lot of DB queries as Craft will be querying the database for each category. You can give Craft all the help you can with something like this.

{# First, retrieve all of your events categories #}
{% set cats = craft.categories.group('events').find() %}

{# Get the IDs of all categories related to this entry #}
{% set relatedCats = craft.categories.group('events').relatedTo({sourceElement: entry}).ids() %}

{# Test if the current category ID is in the array of related category IDs #}
{% for cat in cats %}
    &lt;a href="{{ cat.url }}" {% if cat.id in relatedCats %}class="active"{% endif %}&gt;{{ cat.title }}&lt;/a&gt;
{% endfor %}