Drupal Answers Asked by Paul Canning on February 3, 2021
I have a content type (Type A) that has an Entity Reference field to another content type (Type B).
Type B has 3 fields and 2 display modes. Display A shows two of the fields, Display B shows the other field.
In the display settings for Type A, the display mode for the Type B entity is set to Display 1.
On the template for Type A, I can use {{ content.field_type_b }}
and the two fields are shown.
Now, I want to be able to output the field again, but as Display 2, in a different part of the template.
In a pseudo twig code way, I’d imagine something like {{ content.field_type_b|display_mode('display_2') }}
I have heard suggestions for Display Suite, but I tried this and it seems whilst you can clone a field, there is no option to render it as an entity with a display mode.
I also found Twig Tweak, which I think might work, however, the documentation is beyond terrible and I cannot see how I’d actually use it (the cheat sheet lacks all manner of help).
If this is not possible in Twig, could this be achieved in a hook? Bearing in mind, the field I want to render in Display 2, is a nicely rendered map, so I don’t want to simply get the field value, it has to be using the display mode.
How to display a reference field twice with the help of EVA:
Install EVA.
Add a new View.
Add a display "EVA".
Add the Entity Reference field to FIELDS and configure the Formatter to "Rendered entity" and set the view mode Display 2
.
The EVA display includes the section ENTITY CONTENT SETTINGS, choose the entity type Content
and bundle Type A
.
In the ADVANCED section add a contextual filter for Content: ID
.
Save the View.
Now the new field is visible in the field UI of the content type Type A
and you can drag'n'drop it to the final position.
Answered by 4k4 on February 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP