markup / oembed-bundle
一个包含定义oEmbed提供者并提供模板中oEmbed渲染的捆绑包。
2.0.0
2020-01-30 08:31 UTC
Requires
- php: >=7.1
- symfony/framework-bundle: ^3.4|^4|^5
- twig/twig: ~1.12|~2.0
Requires (Dev)
- guzzlehttp/guzzle: ~6.1
- phpstan/phpstan: ^0.12.5
- phpunit/phpunit: ^7
- symfony/console: ^3.4|^4|^5
Suggests
- guzzlehttp/guzzle: For making OEmbed requests using Guzzle
- symfony/console: To use CLI OEmbed scripts.
This package is auto-updated.
Last update: 2024-08-29 04:03:19 UTC
README
安装
您可以使用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。