I'm super new to both Craft and Twig so, apologies in advance!!
I'm looking to determine if the current entry I'm on is in a loop being called on that page.
I have loop that goes through the entries of a category and displays them. If I'm currently viewing an entry that also appears in the loop, I would like to add an "active" class to the matching entry in the loop.
I have been trying to possibly match the URL segment with an answer like the one found here but I need to the segment name to by dynamic.
Currently I have:
{% for entry in craft.entries.section('category_name').limit(4) %}
<p>{{ entry.title }}</p>
{% endfor %}
And would like it to be like:
{% for entry in craft.entries.section('category_name').limit(4) %}
IF ENTRY IN LOOP MATCHES CURRENT ENTRY PAGE I'M ON.. ADD CLASS
<p class="active">{{ entry.title }}</p>
ELSE
<p>{{ entry.title }}</p>
END IF
{% endfor %}