0

I'm trying to create a custom node template in drupal 8.

I've added the content type and am displaying them in the Front Page view.

I would like to render each field in the in the the node template (node--content-type.html.twig).

Using the recommended {{ content.field_name }} syntax, causes the node to print nothing except the title.

Are there any prerequisites to using this syntax, what am I missing here?

2
  • Did you create that content type by UI or by your own module? I you did it by module, you need to fill the content array by yourself. Commented May 19, 2017 at 17:25
  • Use the correct machine name of the field, If Title is working means machine name must be a problem. Please check it Commented May 20, 2017 at 7:53

1 Answer 1

0

Ended up installing a fresh copy of Drupal and re-adding the content type (through the UI as before). After that it worked fine.

Not sure why that happened, no time to debug, will just continue with this install.

I suspect either I broke the the 'Frontpage' view while fiddling, or one of the Modules was breaking it, perhaps Twig Field Value.

I need to now access a multi value field in Twig, thinking something like {{ content.field_name.0 }}. I need to access the array directly without the use of a foreach loop, because they fit into different parts of the html layout.

Thanks for the responses!

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.