0
$nodeObj = Drupal::service('entity_type.manager')->getStorage('node')->loadByProperties(['type' => 'books' ]);

$nodeObj has field 'field_book_image' and 'target_id' => string(2) "65" in node preprocess we can get file URL $file = File::load($target_id);

but is there any way I can print image field directly in node template with current language

{{ item.translation(langId).field_book_image.entity }}

{{item.field_book_image.entity.uri.value}}

{{ `file_url(node.field_book_image.entity.uri.value) }}`

but none of above giving Image path or Image value

  • If you are in node template you can just do like this {{ content.field_book_image }}. – user72672 Aug 30 '19 at 9:19
  • @Jdrupal I'm in node template and for that node this is possible but for I m printing value for other nodes by doing query $nodeObj – mintra Aug 30 '19 at 9:29
  • Ok, if node is the other node you should be able to do it like this, <img src="{{ file_url(node.field_book_image.entity.uri.value) }}">. – user72672 Aug 30 '19 at 9:31

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.