如何在Drupal 7中的模板中呈现Youtube缩略图 [英] How to render a Youtube thumbnail in a template in Drupal 7
问题描述
我正在使用以下模块:
- 媒体
- media_youtube
- 样式
,并希望在模板(.tpl)中呈现Youtube视频的缩略图。我应该使用哪个主题功能以及什么参数?
and would like to render a thumbnail of a Youtube video in a template (.tpl). Which theme function should I use and with what params?
我最好的一个例子是:
$my_media['style_name'] = 'unlinked_thumbnail';
print theme('file_styles',$my_media);
其中$ my_media是一个包含fid,uri,filename,filemime等的数组。
where $my_media is an array containing fid,uri,filename,filemime etc.
由于我对Drupal很新,所有我对模块源代码的理解尝试都失败了。我觉得我已经尝试了所有可能的youtube和styles模块中定义的风格名称组合,而没有得到任何输出。
Since i'm very new to Drupal, all my attempts to make sense of the modules source code have failed. I feel like I have tried all possible combinations of style names defined in the youtube and styles module without getting any output.
仅使用
print theme('media_youtube_video',$my_media);
你们怎么做?
推荐答案
在 media_youtube
模块代码中挖掘一个函数,在中包含/ media_youtube.formatters.inc 调用
media_youtube_file_formatter_image_view()
。您可以使用以下代码来呈现缩略图:
Digging around in the media_youtube
module code there's a function that will build this up for you in includes/media_youtube.formatters.inc
called media_youtube_file_formatter_image_view()
. You can use code like the following to render the thumbnail image:
// Make sure the correct include file is loaded
module_load_include('inc', 'media_youtube', '/includes/media_youtube.formatters.inc');
// Load the file
$file = file_load($my_media['fid']);
// Set up the settings array with your image style
$display['settings'] = array('image_style' => 'unlinked_thumbnail');
// Get the render array for the thumbnail image
$image_render_array = media_youtube_file_formatter_image_view($file, $display, LANGUAGE_NONE);
// Render it
print render($image_render_array);
这篇关于如何在Drupal 7中的模板中呈现Youtube缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!