i have a content type "actuality" with a reference to an other content type "event". In "event" i have a "field_date" which i want to print into my "actuality" node. What is the best way to do that ?

I've already created a template node--actuality.html.twig and trying to print inside node.field_event_associated.field_date but it's not working.

Regards,

up vote 5 down vote accepted

For any type you of field get the value directly like you wrote node.field_name.value. But for reference type you can't get the value directly. For reference type you have to write

ex.:

node.field_team_location.entity.name.value

and for uri u can write: node.field_team_location.entity.uri.value

  • Hi and thanks for your answer. I don't manage to access my values like this, the only thing i can do is : {{ content.field_evenement_associe[0]['#url'].options['entity'].field_date_event.value }} but i find it very complicated. Do i miss something ? – lchabrand Dec 12 '16 at 5:59
  • 1
    If you apply the example from this answer you get a shorter version: {{ node.field_event_associated.entity.field_date.value }}. – 4k4 Dec 12 '16 at 7:59
  • Thanks i get some results with this version. By the way, where can i find this in Drupal doc ? Regards – lchabrand Dec 12 '16 at 23:48
  • You can find it in twig template documentation of drupal 8. – Deepak modi Dec 13 '16 at 13:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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