Error while trying to use dynamic routing to pass variables to the template and using them So i'm trying to pass the variables from a dynamic route to a template and then to use those variables to filter trough entries.
the catch is that the same template is used to display an "organic"(by organic i mean that it is set up from the CP) category as well.

This is the routes.php

'shop/(?P&lt;segmentCategory&gt;(new|used))/(?P&lt;segmentEntryType&gt;[a-z]+)' =&gt; 'shop/category',


And this is from the template:

{% if segmentCategory is defined %}
    {% set category = craft.categories(segmentCategory) %}
    {% set games = craft.entries({
        type: segmentEntryType,
        relatedTo: ['and',
            { sourceElement: craft.entries.section(segmentEntryType).status(null) },
            { targetElement: category }
        ]
    }) %}
{% else %}
    {% set entries = craft.entries.relatedTo(category) %}
{% endif %}


The error:

    Object of class Craft\ElementCriteriaModel could not be converted to string


craft/templates/shop/category.html(47)

47 {% extends "_layout" %} ||||||||||||||(Highlighted)||||||||||||||||
48 {% block content %}
Try this:

{% set category = craft.categories(segmentCategory).first %}


Without the first at the end, you're setting category to an ElementCriteriaModel. Which would be fine in many cases, but it's not an acceptable variable type for targetElement.

Ditto for the sourceElement:

craft.entries.section(segmentEntryType).status(null).first