0

I need to get the current language in the html.html.twig file of my theme. In my page.html.twig I can use:

{% if (language.getId() == 'nl') %}

This does not work in my html.html.twig. Any ideas?

2 Answers 2

1

Add the following snippet in your .theme file:

function MYTHEME_preprocess_html(&$variables) {
  $variables['lang'] = \Drupal::languageManager()->getCurrentLanguage()->getId();
}

Then, in your html.html.twig file use:

{% if (lang == 'en') %}
  // Your action
{% endif %}
1

In Drupal 9 the answer is this:

{{ node.langcode.langcode }}

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.