缩略图SonataMediaBundle

时间:2014-07-15 14:59:39

标签: symfony thumbnails sonata-media-bundle

SonataMediaBundle中缩略图的含义是什么,它是一个图像,缓存中的图像,图像调整大小?特别是在模板中:

有什么区别 渲染缩略图:

{% thumbnail media, 'small' %}

和:

{% media media, 'small' %}

它呈现相同的东西,即图像!

Thnaks!

1 个答案:

答案 0 :(得分:1)

理解这种疑惑的最好方法是查看源代码;

媒体
https://github.com/sonata-project/SonataMediaBundle/blob/master/Twig/Extension/MediaExtension.php#L69

<强>缩略图
https://github.com/sonata-project/SonataMediaBundle/blob/master/Twig/Extension/MediaExtension.php#L123

模板
https://github.com/sonata-project/SonataMediaBundle/blob/master/Resources/views/Provider/thumbnail.html.twig

从模板文件夹中可以看到:
 的 thumbnail.html.twig

<img {% for name, value in options %}{{name}}="{{value}}" {% endfor %} />

缩略图扩展程序显示媒体的缩略图图像

基于您想要查看的媒体,媒体扩展程序将加载相应的模板(view_dailymotion.html.twig,view_file.html.twig,view_image.html.twig,view_vimeo.html.twig,view_youtube.html.twig )将显示&#34;真实&#34;媒体

如果媒体是图片,则两者的结果都相同

{% thumbnail media, 'small' %}  

{% media media, 'small' %}  

view_image.html.twig 的模板实际上是:

<img {% for name, value in options %}{{ name }}="{{ value }}" {% endfor %} />

相反,如果媒体是youtube媒体
  view_youtube.html.twig

{% if options.html5 %}
    <iframe width="{{ options.player_parameters.width }}" height="{{ options.player_parameters.height }}" src="//www.youtube.com/embed/{{ media.providerreference }}?{{ options.player_url_parameters }}" frameborder="{{ options.player_parameters.border }}"{% if options.player_parameters.allowFullScreen %} allowfullscreen{% endif %}></iframe>
{% else %}
    {% if options.player_parameters.allowFullScreen %}
        {% set allowFullScreen = "true" %}
    {% else %}
        {% set allowFullScreen = "false" %}
    {% endif %}
    <object width="{{ options.player_parameters.width }}" height="{{ options.player_parameters.height }}">
        <param name="movie" value="//www.youtube.com/v/{{ media.providerreference }}?{{ options.player_url_parameters }}"></param>
        <param name="allowFullScreen" value="{{ allowFullScreen }}"></param>
        <param name="allowscriptaccess" value="{{ options.player_parameters.allowScriptAccess }}"></param>
        <param name="wmode" value="{{ options.player_parameters.wmode}}">

        <embed
            src="//www.youtube.com/v/{{ media.providerreference }}?{{ options.player_url_parameters }}"
            type="application/x-shockwave-flash"
            allowscriptaccess="{{ options.player_parameters.allowScriptAccess }}"
            allowfullscreen="{{ allowFullScreen }}"
            width="{{ options.player_parameters.width }}"
            height="{{ options.player_parameters.height }}"
            wmode="{{options.player_parameters.wmode}}">
        </embed>
    </object>
{% endif %}