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 .
1 Answer
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.
-
You'll need to enable this module twig_field_value if you want field_label and field_value filter to work.– guilhomCommented Jul 7, 2017 at 11:51
-
-
1Good 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…– feeelaCommented 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
{{ content.field_machine_name }}
does not work in a basic node template, something else is wrong and there is not enough information here.