Search code examples
youtubetypo3blogsfluidtypo3-8.x

How do I output a YouTube video with EXT:blog from a page's resources in Fluid?


In the context of EXT:blog (which may or may not be relevant) on TYPO3 8.7 I added a YouTube video under Resources > Files > Media > Add media by URL. This results in a reference to a .youtube file.

Within List\Post.html, a Fluid template which overrides EXT:blog's Post.html, I get access to the post.media array. post.media contains a FileReference. When rendering that using <f:image src="thatreference.uid" treatIdAsReference="1" .../> I do get the video's thumbnail.

How do I determine whether a post.media entry refers to a YouTube video and how do I render that video instead of the thumbnail image? I could not find any useful properties on that FileReference (such as media type or YouTube video ID) yet. Do I need to go another route?


Solution

  • Media, including images and videos, can be output using the f:media ViewHelper:

    <f:media file="{thatreference}" width="400" height="375"/>
    

    To determine the resources media type use {thatreference.originalResource.originalFile.type}. A value of 4 stands for video, 2 stands for images:

    <f:if condition="{thatreference.originalResource.originalFile.type} == 4">…</f:if>
    

    The original YouTube URL can be read from {thatreference.originalResource.publicUrl} and various other properties such as preview dimensions (useful for calculating aspect ratio) from {thatreference.originalResource.properties}.