shadesoft/twig-video-box

该软件包已被废弃,不再维护。未建议替代软件包。

Twig 扩展,简化视频嵌入。

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

This package is auto-updated.

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


README

Twig 扩展,简化视频嵌入。

目前支持 YouTube。其他视频分享网站将稍后提供。

安装

打开命令行控制台,进入您的项目目录,然后执行以下命令以下载此软件包的最新稳定版本

$ composer require shadesoft/twig-video-box

此命令需要您已全局安装 Composer,具体请参阅 Composer 文档的安装章节

将软件包包含到 Symfony 3-4 容器中(如果 autowire 和 autoconfigure 设置为 true)

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

ShadeSoft\Twig\YouTubeExtension: ~

将软件包包含到 Symfony 2 容器中

# app/config/services.yml

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

将软件包包含到 Slim 框架的 Twig 视图渲染器中

// src/dependencies.php

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

用法

将 \ShadeSoft\Twig\YouTubeExtension 添加到您的 Twig 环境的依赖项中(或包含到上述框架之一),然后您可以使用过滤器

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