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

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

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

<pre><code>//routes.php file
return [
  'enSite' =&gt; [
      'example/{tag}' =&gt; ['template' =&gt; 'example/_index.html',
                          'name' =&gt; 'example',
                         ],
  ],
  'nlSite' =&gt; [
      'voorbeeld/{tag}' =&gt; ['template' =&gt; 'voorbeeld/_index.html',
                            'name' =&gt; 'example',
                           ],
  ],
];
</code></pre>

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

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

<p>Does anyone know how to get the current applied route in Craft?</p>

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

CC BY-SA 4.0
2020-01-10T20:02:41.253Z
Check this: http://craftsnippets.com/articles/url-macro - looks like it might be solving what you're trying to do, using macros.
SamC
CC BY-SA 4.0
2020-01-14T08:53:51.340Z
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
<templating><localization><routes><multi-site><routing>
How can i get the current applied route in CraftCMS?
# How can i get the current applied route in CraftCMS?

(Asked by: username_0 on 2020-01-10)

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.

**Tags:** templating, localization, routes, multi-site, routing
> **Comments:**
> **username_1**: Check this: http://craftsnippets.com/articles/url-macro - looks like it might be solving what you're trying to do, using macros.  
> **username_0**: 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.  

---

## 0 answers

