Skip to content

Video Field ​

A video: either a file from a media source, or a link to YouTube or Vimeo. The field works out which it is and fetches what it can about it.

Settings: source and file path, as for a file.

What arrives in the template depends on the provider ​

Every case gives you provider, url and embed_video. Beyond that they differ, and the difference bites:

Providerthumbnail
youtubeAn array of sizes — default, medium, high, standard, maxres, each with url, width, height. Plus a ready preview
vimeoA string with the URL, plus thumbnail_width and thumbnail_height
video (an uploaded file)None — there is nothing to fetch it from

thumbnail is an array for YouTube and a string for Vimeo

The same key holds different shapes. A template written against a YouTube video and then fed a Vimeo one prints Array — or nothing. Branch on provider, or use preview where it exists.

YouTube and Vimeo:

html
<iframe src="{$video.embed_video}" width="600" height="400" frameborder="0"></iframe>

An uploaded file:

html
<video controls poster="/{$video.preview}">
    <source src="/{$video.url}">
</video>

An uploaded file has no preview of its own until somebody picks one: it is the Preview box in the field's info window, beside the title and the description. Leave it empty and the poster attribute comes out blank.

Title and description come from the provider, so an embedded video can be labeled without retyping anything.

© PageBlocks 2019-present