I'm making a portfolio website, where the url's look like "projects/project-name". There is also an overview page with all the projects that is under "projects" on itself.

I'm using a Structure for this, but I go to the 404 page when I'm just trying to go to "projects" without the slugs.

Is there a way of using a structure without a slug?

  • I am also interested in this question. I created a navigation with a structure. Now I want to get rid of this slugs. Because it will appear in the sitemap. And this pages are error pages without a template. Is there a way to create structure entries without a slug?
    – Slowwie
    Aug 13 '20 at 5:53

You'll need to create a listing template for the base /projects URL, and make that template render for that URL.

The easiest way is to just add a template called /templates/projects/index.html, in which case Craft will automatically render that template whenever a user hits example.com/projects.

Another way is to create a dynamic route, and point it to whatever template you want rendered for the /projects URL.

Obviously, inside your listing template you'll need to pull the Structure entries manually, i.e. by doing something like this:

{% for entry in craft.entries.section('projects') %}
        <h2><a href="{{ entry.url }}">{{ entry.title }}</a></h2>
{% endfor %}

Note that if you don't pass an .order() parameter to your craft.entries query, Craft will use the default order, which is the "manual" structure order for Structure sections.

Also note that if your Structure is multi-level, you'll probably want to use the {% nav %} tag over the basic {% for %} loop:

{% nav entry in craft.entries.section('projects') %}
        <a href="{{ entry.url }}">{{ entry.title }}</a>
        {% ifchildren %}
                {% children %}
        {% endifchildren %}
{% endnav %}

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.