I'll explain a bit of the structure of the content and then proceed to the issue.
So i have a website with a shop in it with the url mysite.com/shop/, it is an channel section, and its template is located at craft/templates/shop/index.html.
The shop is divided in to 2 categories - "new", and "used", the url for each is mysite.com/shop/(used or new), and its template is located at craft/templates/shop/category.html.
The section(channel) shop that is mentioned above also has multiple entry types, for example "televisions", "consoles", "computers"... and each one has a required category field to chose one of the above(new or used), and the url for those entries is 'shop/{condition.first().slug}/{type}/{slug}' (the condition field is the category).
Now to what i'm trying to do, and whats the issue. I want the user to be able to filter through entry types within the category template. what i mean is that te used could click "show only tv's" and a url with the new filter will load but with the same template, so the url would look like that: mysite.com/shop/used/television/
To accomplish that i've made a new dynamic route by adding the nex line to my routes.php:
'shop/(?P<segmentCategory>(new|used))/(?P<segmentEntryType>[a-z]+)' => 'shop/category',
And the template goes like this(the twig part only):
{% if segmentCategory is defined %}
{% set category = craft.categories.slug(segmentCategory).first() %}
{% set entries = craft.entries({
type: segmentEntryType,
relatedTo: ['and',
{ sourceElement: category },
{ targetElement: craft.entries.type(segmentEntryType).status(null).first }
]
}) %}
{% if not entries %}
{% exit 404 %}
{% endif %}
{% else %}
{% set entries = craft.entries.relatedTo(category) %}
{% endif %}
{% for entry in entries %}
{{ entry.title }}
{% else %}
There are no entries matching you criteria right no, please try again in a few days.
{% endfor %}
I'm having two issues with this code.
First: {% if not entries %}
never executes, even if i enter complete nonsense in the url.
Second: the array entries
is never outputs anything...
Thanks ahead!