How to get current language in html.html.twig of theme

by Stef   Last Updated January 11, 2018 12:07 PM

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?

Tags : 8 theming


Answers 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 %}
Stef
Stef
January 11, 2018 11:20 AM

Related Questions


Features can export everything?

Updated March 26, 2015 10:02 AM


No image style found

Updated March 29, 2015 15:02 PM


Best way to have 5 or 6 themes in one site drupal 7

Updated April 09, 2015 22:03 PM