Sharing a template with identical category and tag name I'm trying to stay as DRY as possible here and sharing one template for a news list view; all, category and tag all sharing the same template (and trying to refrain from having a category or tag segment). My query isn't returning any results when the segment 2 (in this case the url encoded tag or category slug) when there is a tag and category that share the same name. Example, 'design' is a category for design related posts; 'design' is a tag for posts that featured a design service within the 'portfolio' category. My template code is below. Is there a work around here or do I need to have a second segment for tag/category (i.e. .com/news/category/design and .com/news/tag/design - or one or the other to differentialte)

{% if category is defined %}

    {% set newsPosts = craft.entries.section('news').relatedTo(category).limit(5) %}

{% elseif tag is defined %}

    {% set tag = craft.tags.groupId(3).name(tag).first() %}

    {% set newsPosts = craft.entries.section('news').relatedTo(tag).limit(5) %}

{% else %}

    {% set newsPosts = craft.entries.section('news').limit(5) %}

{% endif %}
If the url for posts with the category design is .com/news/design and the url for posts with the tag design is also .com/news/design, then you are not going to be able to see both lists. You do need that extra segment in the url.

What I do to stay DRY is let Craft route tags and categories to different templates (so you don't have to repeat the is this a category or a tag logic). Then on the different templates, use a macro or include for the common code.

Here is what the categories page looks like with a macro:

{% extends '_layout' %}
{% import '_macros/_news' as news %}

{% set newsPosts = craft.entries.section('news')relatedTo(category).limit(5) %}

{% block content %}
  &lt;h1&gt;Entries with category {{category.title}}&lt;/h1&gt;
  {{ news.index(newsPosts) }} {# all the shared code is in news.index() #}
{% endblock content %}