shadesoft/twig-video-box

This package is abandoned and no longer maintained. No replacement package was suggested.

Twig extensions for making video embedding easy.

v1.1 2020-02-04 23:05 UTC

This package is auto-updated.

Last update: 2023-10-02 20:19:44 UTC


README

Twig extensions for making video embedding easy.

Currently supports YouTube. Other video sharing sites will be available later.

Installation

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.

Including into Symfony 3-4 container (if autowire and autoconfigure is set to true)

# app/config/services.yml for Symfony 3 or config/services.yaml for Symfony 4

ShadeSoft\Twig\YouTubeExtension: ~

Including into Symfony 2 container

# app/config/services.yml

shadesoft.twig.video_box.youtube_extension:
    class: ShadeSoft\Twig\YouTubeExtension
    tags:
        - { name: twig.extension }

Including into Slim Framework's Twig view renderer

// src/dependencies.php

// ...
$container['view'] = function($c) {
    //...
    $view->addExtension(new ShadeSoft\Twig\YouTubeExtension);
    //...
}

Usage

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 #}