If we want to load media entity fields on node twig template. It's easy to load media entity, Please have a look..
{# call to media entity fields on node twig #}
{% for key, item in node.field_document_entity_browser %}
// This is the node field which is connect to media field `field_document_entity_browser`..
{% if node.field_document_entity_browser[key].entity %}
// here we are rendering media entity field which machine name is `field_capt2120`..
{{ node.field_document_entity_browser.entity.field_capt2120[key].value }}
// here we are rendering media entity image field which machine name is `field_media_image`..
{%if item.entity %}
{% set media = item.entity %}
{% set file = media.field_media_image.entity %}
{% set uri = file_url(file.uri.value) %}
<img src="{{ uri }}" alt="{{ media.name.value }}" />
{% endif %}
{% endif %}
{% endfor %}
Note: If have any suggestions or issue regarding 'Media entity fields render in drupal 8 Node Twig template.' then you can ask by comments.
{# call to media entity fields on node twig #}
{% for key, item in node.field_document_entity_browser %}
// This is the node field which is connect to media field `field_document_entity_browser`..
{% if node.field_document_entity_browser[key].entity %}
// here we are rendering media entity field which machine name is `field_capt2120`..
{{ node.field_document_entity_browser.entity.field_capt2120[key].value }}
// here we are rendering media entity image field which machine name is `field_media_image`..
{%if item.entity %}
{% set media = item.entity %}
{% set file = media.field_media_image.entity %}
{% set uri = file_url(file.uri.value) %}
<img src="{{ uri }}" alt="{{ media.name.value }}" />
{% endif %}
{% endif %}
{% endfor %}
Note: If have any suggestions or issue regarding 'Media entity fields render in drupal 8 Node Twig template.' then you can ask by comments.
No comments:
Post a Comment