markup/oembed-bundle

一个包含定义oEmbed提供者并提供模板中oEmbed渲染的捆绑包。

安装次数: 55,712

依赖关系: 0

建议者: 0

安全: 0

星标: 4

关注者: 5

分支: 2

开放问题: 0

类型:symfony-bundle

2.0.0 2020-01-30 08:31 UTC

This package is auto-updated.

Last update: 2024-08-29 04:03:19 UTC


README

Build Status

安装

您可以使用composer安装此捆绑包,或者直接将包添加到您的composer.json文件中。

   composer require markup/oembed-bundle

安装包后,您只需将捆绑包添加到您的AppKernel.php文件中

   // in AppKernel::registerBundles()
   $bundles = array(
       // ...
       new Markup\OEmbedBundle\MarkupOEmbedBundle(),
       // ...
   );

关于

这个Symfony2捆绑包允许您轻松地根据需要定义与OEmbed提供者的集成,而无需使用如Embed.ly之类的服务。

用法

假设您想使用OEmbed包括YouTube视频 - 您可以在config.yml文件中设置提供者作为语义配置

    markup_o_embed:
        providers:
            youtube:
                endpoint: http://www.youtube.com/oembed
                scheme: "http://www.youtube.com/watch?v=$ID$"
                code_property: html

然后您可以在模板中通过引用媒体ID和提供者来渲染oEmbed块

    {{ markup_oembed('dQw4w9WgXcQ', 'youtube', {}) }}

或者如果您已经将类Markup\OEmbedBundle\OEmbed\Reference的对象传递到模板中

    use Markup\OEmbedBundle\OEmbed\Reference;

    $oEmbed = new Reference('dQw4w9WgXcQ', 'youtube');
    $twig->render('my_template.html.twig', array('oembed' => $oEmbed));

您可以稍作不同的引用

    {{ markup_oembed_render(oembed, {}) }}

许可证

在MIT许可证下发布。请参阅LICENSE。