I have a main structure as my navigation. Within this structure I have multiple image galleries. I want to make the image gallery's urls dynamic.

If I define a gallery within the structure entry:

The url of the images in the gallery (which is a channel) should be:

now I would like to have a route which catches all of the ?type=gallery entries and load the "gallery/_entry" template.

It shouldn't matter how deep in the structure the ?type=gallery is.

I don't seem to be able to do this within the CP, and I've never used advanced routing...

Any help appreciated!


Maybe I need to specify a little further:

I have a structure called "pages" which acts as the main structure.
I have a channel that is called "galleries" where I can upload images and assign a category. In my main structure I can assign galleries from within a matrix block and choose a category. That way I can regroup multiple entries from the channel "galleries" in a structure entry.

The urls of the galleries should be completely dynamic:

https://mysite.com/sport/gallery holds multiple gallery entries where each of these galleries should have a url the following way:
https://mysite.com/sport/gallery/gallery2 ...

another gallery collection could be here: https://mysite.com/karting/galleries/ whith links like that: https://mysite.com/karting/galleries/gallery3

I know I could specify the entry url of one gallery the following way in the "galleries" section url settings:

{{ craft.entries.id(65).locale('de').first.uri }}/{slug}
where the id is the id of e.g. https://mysite.com/sport/gallery/ structure entry.

But that works only for one gallery.

I could create a route for "sport/gallery/*" and assign the "gallery/_entry" template to it. But that way I would have to create a route for every gallery, which is not completely obvious, nor intuitive on a editor's point of view.

In fact this is almost a duplicate of this question:
dynamic urls for channel/structure that's linked to the main structure


  • You don't have to do this in the control panel. You could do it completely in the template. Why do you want to load a specific template based on the query string when you already have "gallery" in the url structure? Not trying to be mean genuinely curious about your use case! Commented Apr 12, 2019 at 21:55
  • problem is hitting that "gallery/_entry" template. If I don't define a route, it will generate a 404 page.
    – outline4
    Commented Apr 15, 2019 at 10:27

1 Answer 1


You can do this completely in the template. Have the structure entries resolve to a route like gallery/_router and then inside that template you could use this code to include the template of your choice:

{% switch craft.app.request.getParam('type') %}

    {% case "gallery" %}

        {% include "gallery/_entry" %}    

    {% case "anotherParam" %}

        {% include "gallery/_anotherParam" %}

     {% default %}

        {% include "gallery/_default" %}   

{% endswitch %}
  • Problem is that the page where the ?type parameter is, will generate a 404 error when you don't specify a route... I edited the question to better explain the situation...
    – outline4
    Commented Apr 15, 2019 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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