I created a custom bundle (content type) and I've created fields
One of those field is a file type field, is a video file, stored in the private storage. I installed the videojs module to allow to watch the video.
I need to show this field twice in the node page. One in the generic file formatter that allows the user to download the file, and I also need to play the video. I decided to set up as generic file formatter and customize the twig template to show again with the video player.
I achieve to show twice with the settings formatter (generic file) with this code in the node--mybundle--full.html.twig template
{{ content.field_sd_video }}
But I don't know to show in the video player.
I saw the videojs theme function
But I don't know how to get the field value in the twig template or in template_preprocess_node function and format it as videojs player
Comments
Comment #2
ferriol CreditAttribution: ferriol commentedI finally found the solution, I put this code in preprocess node function. It has to be easy, but not easy to know how ;)
and I only has to add this line in twig file:
{{ video_caption }}
in my case node--mybundle--full.html.twig template
For those arrive here looking for something similar
I was inspired by Twig Recipes on page 41
It was usefull for me Twig debugging. Playing with kint and node variable and the classes used to wrap the information. Then I found that the field comes with FileFieldItemList and then I found the view method that uses EntityViewBuilderInterface