Twig extensions for making video embedding easy.
Currently supports YouTube. Other video sharing sites will be available later.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require shadesoft/twig-video-box
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
# app/config/services.yml for Symfony 3 or config/services.yaml for Symfony 4
ShadeSoft\Twig\YouTubeExtension: ~
# app/config/services.yml
shadesoft.twig.video_box.youtube_extension:
class: ShadeSoft\Twig\YouTubeExtension
tags:
- { name: twig.extension }
// src/dependencies.php
// ...
$container['view'] = function($c) {
//...
$view->addExtension(new ShadeSoft\Twig\YouTubeExtension);
//...
}
Add \ShadeSoft\Twig\YouTubeExtension to your Twig environment's dependencies (or include into one of the frameworks above), then you can use the filters:
{{ 'youtube_video_id'|youtube }} {# Renders YouTube with the default dimensions (560x315) #}
{{ 'youtube_video_id'|youtube(640) }} {# Renders YouTube with the width given (640x315) #}
{{ 'youtube_video_id'|youtube(640, 480) }} {# Renders YouTube with both dimensions given (640x480) #}
{{ 'youtube_video_id'|youtube('100%') }} {# Renders YouTube with the width fluid (100% x 315px) #}
{% set content = '<div><p>Youtube video:</p>http://youtu.be/video_id</div>' %}
{{ content|youtubeBoxes|raw }} {# Renders the div with the p and the embedded video inside content #}
{# With this you can render multiple video boxes in a html content, you can simply use any valid YouTube url to the video #}
{# The width and height parameters can be used here, too #}