Code snippet giúp bạn in giá trị entity reference trong twig template Drupal 8/ Drupal 9.
Với trường là limited ( limited fields)
{{ node.field_REFERENCE_NODE.entity.field_name.value }}
Với trường là unlimited ( unlimited fields)
{% for key,value in node.field_REFERENCE_NODE.value %}
{# link to reference node #}
<a href="{{ path('entity.node.canonical', { 'node' : content.field_REFERENCE_NODE[key]['#node'].nid.value}) }}">{{ 'read more'|t }}</a>
{# get field image and alt #}
<img src="{{ file_url(content.field_REFERENCE_NODE[key]['#node'].field_image.entity.uri.value) }}"
alt="{{ content.field_REFERENCE_NODE[key]['#node'].field_image.alt }}"/>
{# get title#}
<p>{{ content.field_REFERENCE_NODE[key]['#node'].getTitle() }}</p>
{% endfor %}