2
{% for item in contents.hotel_attractions.field_banner_image_slider %}
    <h1>{{item.entity.field_main_caption.value}}</h1>
{% endfor %}

field_banner_image_slider is a paragraph entity. field_main_caption is a field of the paragraph.

I have used $node->getTranslation($language) to get the translated node. In twig with the above code it prints the default language value without translation. In the same node the contents which are not from a paragraph entity prints the translated value correctly.

I have enabled the translations for paragraph fields from configurations.

  • 1
    You can get the translated paragraph in preprocess the same way you get the translated node. But normally you don't need so much code to render a paragraph field, if you theme it in a paragraph template. – 4k4 Jan 23 '18 at 13:10
  • @4k4 I didn't get what you said. Could you please elaborate more :) – i am batman Jan 24 '18 at 3:36
  • If you want to access the paragraph directly, then use $paragraph->getTranslation($language) in preprocess, like you already do for the node. But as said, better let the paragraph render itself and use another template (you see this in the Twig Debug output). – 4k4 Jan 24 '18 at 7:16

Your Answer

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

Browse other questions tagged or ask your own question.