- Issue created by @juagarc4
- Status changed to Fixed
about 1 year ago 7:26am 6 January 2024 Automatically closed - issue fixed for 2 weeks with no activity.
Drupal Core version: 10.1.3
Twig Tweak: 3.2
I want to render a field from a content type which uses Layout Builder for the view mode "full/default".
But the field is not rendered by using:
{{ drupal_field('field_name', 'node', entityId, 'full') }}
On the other hand I have configured, for the same content type, the view mode "teaser" without layout builder
And this time it works properly using:
{{ drupal_field('field_name', 'node', entityId, 'teaser') }}
The output of twig dump for the two cases shows that for the view mode "full", the object to render has been removed, whereas in the second case it remains.
1. Create a content type with some fields
2. Configure the view mode "default" tom use layout builder
3. Configure another view mode (i,e: teaser) to not use layout builder
4. In the corresponding twig template try:
{{ drupal_field('field_name', 'node', entityId, 'full') }} <= Field is not rendered
{{ drupal_field('field_name', 'node', entityId, 'teaser' }} <= Field is rendered
After some investigation I discovered the piece of code responsible for deleting the object from render array:
In the file "LayoutBuilderEntityViewDisplay.php" Line 282 we can see:
After this foreach, the field is not present anymore.
I don't know if this problem should and can be solved in this module or it's maybe a problem on Layout Builder side.
If it's not possible to solve this problem because it probably depends on Layout Builder, it would be nice to have a kind of notice in the documentation, so that one can configure a view mode specifically for that case.
Fixed
3.2
Code
Automatically closed - issue fixed for 2 weeks with no activity.