3

I created a field whose machine name is field_test. I want to show this field in node.html.twig, but when I use {{ content.field_test }}, {{ content.field_test.value }}, or {{ content.field_test[0] }} the field is not printed.

How can I achieve this in Drupal 8.3.5?

12
  • 1
    {{ content.field_test}} is enough. It will work. Check node.html.twig is working or not first . Commented Aug 1, 2017 at 5:53
  • Yes node.html.twig work but {{ content.field_test }} not work.
    – user60258
    Commented Aug 1, 2017 at 6:11
  • 1
    You know you can only print fields configured in the display mode of the content type?
    – 4uk4
    Commented Aug 1, 2017 at 6:23
  • 1
    {{ node }} has access to all fields from the database, for {{ content }} you need to add them first in the content type in Manage Display, where you can also configure how the full HTML markup is formatted.
    – 4uk4
    Commented Aug 1, 2017 at 6:32
  • 1
    I do this but not work.
    – user60258
    Commented Aug 1, 2017 at 10:13

2 Answers 2

4

Uninstalling Field Layout module will solve this. (tested with Drupal 8.6.10, using subtheme built on Barrio Bootstrap 4).

2
{{ content.field_test }}

Should just work but make sure

  • you the field is not hidden by going to admin/structure/types/manage/CONTENTTYPE/display and making sure the field is NOT in the disabled fields
  • its not hidden because of some changes in hook_preprocess_node in your theme or a parent theme

Investigate further either by

  • installing devel and kint modules (kint is a submodule of devel) and {{kint(content)}}
  • within hook_preprocess_node using a xdebug or print or print_r statements

Your Answer

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