0

I have a tranlatable node, and I need to get its translation language. You know, I must to know is current node is in Polish or English. So... below there are my devel dumps from a node in Polish and a node in English. I see that there is a difference in #activeLangcode (x-default and en). But how to get that value? Or is there any better way to check current language of node in twig? Please help.

enter image description here

enter image description here

1
3

A more elegant Drupal way without typing code:

  1. Go to the Manage display of the content type of your node (/admin/structure/types/manage/YOUR_CONTENT_TYPE/display/full). Select your display mode (or use the default). You will notice the field 'Language', move it to the upper side so it gets out of 'Disabled'.
  2. Once you have done that, the language of the node is available in Twig. You can access the id this way {{ node.langcode.langcode }}; or you can access the whole Object to get other data like the name {{ drupal_dump(node.langcode) }}

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.