0

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 .

3
  • 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/…
    – 4uk4
    Commented Jul 7, 2017 at 11:38
  • The field is in the display mode . Commented Jul 7, 2017 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
    Commented Jul 7, 2017 at 14:42

1 Answer 1

1

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.

5
  • You'll need to enable this module twig_field_value if you want field_label and field_value filter to work.
    – guilhom
    Commented Jul 7, 2017 at 11:51
  • I have tried but no luck Commented Jul 7, 2017 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? Commented Jul 7, 2017 at 13:13
  • {{ dump(content) }} renders nothing at all and a white page is returned…
    – feeela
    Commented Jun 12, 2018 at 16:01
  • sounds like content is undefined in your case. Do you have display php errors enabled? Commented Jun 14, 2018 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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