0

For the video media type of drupal 8 i want to render the fields of it into a tag.

i created the template field--media--video.html.twig copy of field.html.twig

i render the field like this :

{% for item in items %}
<source src="{{ item.content }}" type="video/mp4" title="" data-mep-description="" poster="">
{% endfor %}

That is working properly when the display mode that i use to render that video media only contain one field, in this case field_media_video_file

My problem is that i want to add field poster and description to that display mode, but in that case each field is rendered into a new video tag.

i've tried to render the media like this but all the tag are empty:

{% for item in items %}
<source src="{{ item.content.field_media_video_file }}" type="video/mp4" title="" data-mep-description="{{ item.content.field_media_video_description }}" poster="{{ item.content.field_media_video_poster }}">
{% endfor %}

My question : how can i render the different field of that media content type into the twig template?

I found those post regarding this but it did not help me:

Access A Referenced Node's Fields - Field Level Templating

How to get value from {{ item.content }}

  • 2
    You need to create a template for the media entity type, not the field referencing it. Then just set the reference field to point at a view mode to display the Media. You should not be stuffing multiple fields into one field template. – Kevin May 3 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.