1

We are using Layouts (via mytheme.layouts.yml) to create regions for our Node Edit forms. This looks something like...

edit_nodelayout:
  label: 'Edit Node Layout'
  category: edit
  path: templates/panels
  template: edit-nodelayout
  default_region: toplayout
  regions:
    toplayout:
      label: 'Top'
    details:
      label: 'Details'
    other:
      label: 'Other'

We have placed each field for the content-type into the appropriate region via the admin UI. At least one of our fields is a reference field to a Paragraph entity-type.

In our template, which is defined in the yml as /templates/panels/edit-nodelayout.html.yml, we are currently outputting all content as full regions.

{# some html here #}
{{ content.toplayout }}

{# some html here #}
{{ content.details }}

{# some html here #}
{{ content.other }}

How would we access individual items within a region? For example, if within the content.details region, we have placed a field called "Foo", how do we output that individually? We have tried this...

<p>Please enter everything you know about Foo</p>
{{ content.details.foo }}

This becomes interesting when the field called "Foo" is a reference to a Paragraph entity-type. How would we then output individual fields within "Foo" entity?

<p>Output the "bar" field within the "foo" Paragraph type</p>
{{ content.details.foo.bar }}

Any help, pointers to documentation appreciated.

0

That is not how you're supposed to use layout templates as those should be for for placing content, just like normal Drupal regions, and then modify the output using field and node templates. The general idea being to be able to reuse the templates in other places and as such reducing the number of templates needed.

Of course you can output content directly in the layout template. I would recommend you install the Twig Tweak module. You can then use {{ dd() }} to see what is available to you. As an example you can display a field value like this:

{{ node.field_myfield.value }}

It depends on what you want to display, but that's the general idea, very similar to the node template.

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.