I'm using a dynamic route that loads a template. I'm on a multisite setup with a language switch in the header menu.

To be able to switch between sites or languages, the dynamic routes need to have some sort of connection.

I figured out you can define routes in a site-specific context and add extra attributes (e.g. 'name') like this:

//routes.php file
return [
  'enSite' => [
      'example/{tag}' => ['template' => 'example/_index.html',
                          'name' => 'example',
  'nlSite' => [
      'voorbeeld/{tag}' => ['template' => 'voorbeeld/_index.html',
                            'name' => 'example',

Now I can tell craft that the routes with the same name are variants of each other for the language switcher.

All i need now is the "current applied route". I can't find this information anywhere. I was expecting it in craft.app.requestedRoute, but that's not the case.

Does anyone know how to get the current applied route in Craft?

Others with similar issues loop over craft.app.routes.getConfigFileRoutes and match on the route keys, but with tokens like {tag} in your roue this is not an option.

  • Check this: craftsnippets.com/articles/url-macro - looks like it might be solving what you're trying to do, using macros.
    – SamC
    Commented Jan 10, 2020 at 20:02
  • Thanks, but most of the stuff I tried is already based on that article. In the code snippets from the article, they loop over the craft.app.routes.getConfigFileRoutes . The currently applied route is never fetched.
    – jan
    Commented Jan 14, 2020 at 8:53


Your Answer

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