Score:0

How can I print the Layout builder in a node twig template?

eg flag

After enabling Layout builder for Page content. I can see in Manage fields, a new field called layout_builder__layout. I want to print this inside node--page twig template. This should work but it does not. {{ content.layout_builder__layout }}. Printing all the content does display it like this {{ content }} How can I print only the layout builder?

Score:1
ru flag

Layout builder and Manage fields (moving fields inside Manage Display) are mutually exclusive, you use either the first or the second, you can not mix them. As soon as you activate Layout Builder for a node type, the entire Twig render array is only the Layout builder.

So just render {{ content }}, which renders its one and only child {{ content._layout_builder }}

eg flag
Thank you @hudri
Juc1 avatar
eg flag
@hudri suppose I have enabled layout builder for a content type but one one particular node I want to do something different - so I can no longer use {{ content.body }} in the node's twig template ie it renders nothing?
ru flag
No you can't. You could create a `node--NUMERIC_ID.html.twig` overwrite template, and use manually, hard-coded twig in that template to render your fields, e.g. `<div class="my_class">{{ node.field_XXX.0.value }}</div>` etc.
TheodorosPloumis avatar
cn flag
In order to print just a Node field somewhere on the page you can also use the [fieldblock](https://www.drupal.org/project/fieldblock) module.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.