1

We are trying to generate a language dependent link in a custom block we created though the UI and placed it into a region.

If I {{ dump(language) }} in page.html.twig, I've got it there. But not in the block. Is this by design? Where/How can I get access to it?

2

You can solve this with a preprocess hook:

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

The language variable will then be available in your block template as it is in the page one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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