1

I'm porting a site from EE and I'm running into an issue with an existing URL structure not working using routes.

Existing URL Structure: /articles/[year]/[month]/[day]/

I tried creating a route for the above to the articles/index template but it seems no matter what I try I'm returned the 404 page.

Because of the nature of the site, we need users to be routed to the articles/index template no matter what the three child slugs are and then we can display appropriate messaging if an article doesn't exist for the specific date/URL.

Update

It would appear this must be user error as now the expected outcome is working correctly.

Route: articles/[year]/[month]/[day]

Is properly routing users to the articles/index template whether or not an entry exists.

2

When you create a route, the slugs that you use ('year', ' month', 'day') will be made available in your templates as variables. You will need to use these to retrieve the entry(ies) your looking for. Something like:

Update: Sorry, first version had major errors, should be better now.

{% set datetime = year ~ '-' ~ month ~ '-' ~ day %}
{% set entries = craft.entries.section('articles').postDate('and', '>= ' ~ datetime, '< ' ~ datetime|date_modify('+1 day')) %}

{% if entries %}

    {% for entry in entries %}
        <article>
            <h1>{{ entry.title }}</h1>
            {{ entry.body }}
        </article>
    {% endfor %}    

{% else %}
    <article>
        <p>There are no entries for this date.<p>
    </article>
{% endif %}

Untested, but should be close. See this question for another example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.