2

i've made a twig file for my 'test' content type called node--test.html.twig. That works fine using {{ content }} to print the node.

I've a custom field with the machine name field_text, the following prints fine: {{ node.field_text.value }}

For some reason i cant get {{ content.field_text }} to work. I also can't get content.body or any other subset of content to work in any node type.

I must be doing something really daft - thanks for the help

  • The solution was to uninstall Field Layout module (a core - experimental module). – amcc Aug 21 '17 at 12:16
2

content.<field_name> should work. try adding {{ dump(content|keys) }} to your template, does it show anything?

| improve this answer | |
  • i get the following: website/vendor/twig/twig/lib/Twig/Extension/Debug.php:60: array (size=1) 0 => string '_field_layout' (length=13) – amcc Aug 21 '17 at 11:14
  • if relevant - i'm using bootstrap within a subtheme – amcc Aug 21 '17 at 11:18
  • - just tried with other themes, it doesn't make any difference. – amcc Aug 21 '17 at 11:36
  • Do you have anything special installed? Any idea where the _field_layout comes from? I'm using bootstrap aswell, it should work the way you are trying so I'm guessing you are using some module that changes the templates? Try setting debug: true in the twig.config-section in sites/default/services.yml, after that the page source code should tell you which templates are being used. – Stephan Steege Aug 21 '17 at 11:51
  • Field Layout is a core experimental module - can't remember why i enabled it - may have been enabled by something else i was playing with. I've uninstalled it and its all working now! Thanks very much both of you - I will upvote as soon as my newbie reputation status on this forum allows – amcc Aug 21 '17 at 12:15

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.