如何在 Drupal 7 的模板中渲染 Youtube 缩略图 [英] How to render a Youtube thumbnail in a template in Drupal 7

查看:26
本文介绍了如何在 Drupal 7 的模板中渲染 Youtube 缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下模块:

  • 媒体
  • 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 和样式模块中定义的所有可能的样式名称组合,但没有得到任何输出.

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 模块代码中挖掘,有一个函数可以在 includes/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆