2

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,

6

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
  • It will show you the first value, How will get the All value available in entity reference fields – Manmeet Khurana Jun 21 at 14:20
0

If you want to render a properly formatted single field of a referenced entity you'll simply have to use the |view filter on the desired field of the referenced node.

Let's say the field_customer on my parent node references a customer content type entity that holds the customer's address in field_address.

{{ node.field_customer.entity.field_address|view }}

Use the referenced entity's display settings to define the format of the field you want to render.

Example on drupal.org

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.