I'm familiar with the Drupal 8 theming API,as well as all of the theme template suggestions available when Twig debug is enabled. I have created content type named (machine name) events .For overriding node.html.twig I have made node--events.html.twig . In this (node--events.html.twig) file I am trying to get individual values like below: {{content.body}} But it returns null . I have also tried {{ node.field_machine_name.value }} but It is not working for all the fields .

  • If {{ content.body }} not works, then this field is not in the display mode. If .value on a node field doesn't work, the field has no value property. See md-systems.ch/de/blog/techblog/2017/02/20/… – 4k4 Jul 7 '17 at 11:38
  • The field is in the display mode . – Kshitij Soni Jul 7 '17 at 12:11
  • If typing {{ content.field_machine_name }} does not work in a basic node template, something else is wrong and there is not enough information here. – Kevin Jul 7 '17 at 14:42

In my node twig template file I have this which works for me:

{{ content.field_name|field_label }}
{{ content.field_name|field_value }}

This works if the twig_field_value module is enabled.

| improve this answer | |
  • You'll need to enable this module twig_field_value if you want field_label and field_value filter to work. – guilhom Jul 7 '17 at 11:51
  • I have tried but no luck – Kshitij Soni Jul 7 '17 at 12:12
  • 1
    Good point, twig_field_value must be enabled - I forgot about that. Try using {{ dump(content) }} to see what fields are available in the content object. If it's not working it could be a config problem? – Rick Bergmann Jul 7 '17 at 13:13
  • {{ dump(content) }} renders nothing at all and a white page is returned… – feeela Jun 12 '18 at 16:01
  • sounds like content is undefined in your case. Do you have display php errors enabled? – Rick Bergmann Jun 14 '18 at 15:04

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.