Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/ TwigVideoBox Public archive

Twig extensions for making video embedding easy.

License

Notifications You must be signed in to change notification settings

ShadeSoft/TwigVideoBox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwigVideoBox

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