0

I am using contextual filters on the /path/langcode view, where langcode is a contextual filter. How can I get langcode in a template file?

1

You can get the contextual filter argument from the route match:

  $variables['arg_0'] = \Drupal::routeMatch()->getParameter('arg_0');

Usually the route parameters of contextual filters are named arg_0, arg_1 etc. If it doesn't work, check the route definition of this View page with Devel (/devel/routes) or Drupal Console.

Dependent on the Twig template you might need to add a cache context as well:

  $variables['#cache']['contexts'][] = 'route';

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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