Score:0

Get link to content in entity reference field template

za flag

I have an entity reference field set in Manage Display to 'Rendered Entity' and am working with the field's template to conditionally show the link based on the referenced node's published status. I'm using 'Rendered Entity' so I have access to isPublished().

How can I get just the path of the referenced node in the field's template?

Within {% for item in items %}, this works great to get the referenced node's title: {{ item.content['#node'].title.value }}, but I can't find what I need for the url.

in flag
There is already a "Label" field formatter for entity reference fields that allows you to render the title of the referenced entity either as plain text _or as a link_ to the referenced entity. See `web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php` for the implementation of this field formatter. Should you want to customize the output, I suggest you extend this formatter and override the `viewElements()` method.
I sit in a Tesla and translated this thread with Ai:

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.