How do I get the video media path in a theme?

Drupal Answers Asked by MrFox on December 12, 2020

I want to embed a video on a page.

How do I display the field_media_video_embed_field in my twig?

The complicated thing about this is that I am using a view inside tabs.

{{ kint( }} gives me the following output.


In my theme I have used the following code.

$programmes = [];
$view = Views::getView('participating_programmes');
foreach ($view->result as $row) {
  $video = $row->_entity->get('field_pvideo')->referencedEntities();
  $programmes[$nid]['video'] = $video;

Ideally I want to embed the video, but I would be happy if I could just get the field_media_video_embed_field and work from there.

One Answer

It's unclear whether you want to get one or multiple videos:

// get one video media entity
$video = $row->_entity->get('field_pvideo')->entity;
// get multiple video media entities
$videos = $row->_entity->get('field_pvideo')->referencedEntities(); 

Then in Twig for one video:

{{ }}

or multiple videos:

{% for video in programme.videos %}
  {{ video.field_media_video_embed_field.value }}
{% endfor %}

Correct answer by 4k4 on December 12, 2020

Add your own answers!

Related Questions

“&” displaying as “&”

1  Asked on February 28, 2021 by mohk


Confirmation pop up on login submit

1  Asked on February 22, 2021 by vipin-p


Override a node page of specific content with views page

1  Asked on February 21, 2021 by hkguile


Hide Alt and Title for image field

2  Asked on February 20, 2021 by moto


How do I update from 9.0.10 to 9.1.0?

1  Asked on February 19, 2021 by user101999


Adding fields to content type edit form (not to the node itself)

1  Asked on February 18, 2021 by chris-riddell


Uploaded images in theme settings is going to be lost

3  Asked on February 13, 2021 by saidbakr


How to delete a large amount of nodes effeciently during cron?

1  Asked on February 12, 2021 by athakhan


Composer updates .htaccess file when updating

3  Asked on February 11, 2021 by albertski


How to print the Views title in page.tpl.php?

3  Asked on February 10, 2021 by szymon-panecki


May I use Bootstrap-CDN on Subtheme for production site?

1  Asked on February 7, 2021 by leelandra


Alter Webform email body

1  Asked on February 6, 2021 by lus


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP