I have a content type with a field « referenced entity » called field_suggestion_articles
.
User can choose related content and a view displays this list of related content at the bottom of the content. The views uses "content" (display mode, a template like teaser) and not fields.
I use a loop to display this list in node--article--related-content.html.twig
:
{% for key,value in node.field_suggestion_articles.value %}
{# display the title #}
{{ content.field_suggestion_articles[key] }}
{# display a text field #}
{{node.field_suggestion_articles[key].entity.field_resume_suggestion_article.value|raw}}
{% endfor %}
But I don’t know how to get the node urls of these related content.
When I dump node.field_suggestion_articles.value
, I get the target_id
of the node so I guess I should use it to retrieve the url. But I’ve tried a lot of solutions found on Drupal forums and here on stackExchange but without success.
Could you point me in the right direction ?
{{ path('entity.node.canonical', {'node': node.field_suggestion_articles[key].entity.id}) }}
should work i think{{ url }}
.