简体   繁体   English

不调用Drupal主题函数?

[英]Drupal theme function is not called?

I am new to Drupal and trying to create a theme function that create a little iframe for my videos. 我是Drupal的新手,正在尝试创建一个主题功能,为我的视频创建一个小的iframe。 I am calling the function in my menu callback function. 我正在菜单回调函数中调用该函数。 The problem is that the theme function is not called. 问题在于没有调用主题函数。 I tried to append the module name at the beginning of the theme function and also removed and it didn't help. 我试图在主题函数的开头附加模块名称,并且也删除了模块名称,但没有帮助。 I clear the cache every time I make changes and enabled the backtrace in my devel module and I see the following warning: 每次进行更改并在devel模块中启用backtrace时,我都会清除缓存,然后看到以下警告:

warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'mymodule_mobile_mymodue_mobile_build_iframe' not found or invalid function name in call_user_func_array() (line 656 of /var/www/includes/theme.inc). 警告:call_user_func_array()期望参数1是有效的回调,函数'mymodule_mobile_mymodue_mobile_build_iframe'找不到或call_user_func_array()中的函数名称无效(/var/www/includes/theme.inc的第656行)。 => =>

function my_callback_function(){
$output = theme('mymodule_mobile_build_iframe',array(
           'arg1'=> $stream,
           'arg2'=> $node->nid,)
               );
return $output

}
function mymodule_mobile_theme(){

      return array(
        'mymodule_mobile_build_iframe' => array(
        'arguments'    => array(
        'arg1'    => NULL,
        'arg2'   => NULL,),),);
}

function theme_mymodule_mobile_build_iframe($arg1,$arg2){

    $host = 'http://www.myhost.com';

    $output = '<video width="320" height="240" controls="controls"> <source src=
        "'.$host.'/'.$arg1.'/'.$arg2.'/playlist.m3u8" type="video/mp4" />
        Your browser does not support the video tag.
        </video>';

    return $output;
}

Thank you all in advance! 谢谢大家!

I would suspect this is a simple naming problem; 我怀疑这是一个简单的命名问题; is your module called mymodule or mymodule_mobile ? 您的模块名为mymodulemymodule_mobile吗? This will be the same name as your module's .info file (obviously minus the .info ). 该名称将与模块的.info文件相同(显然减去.info )。

If it's called mymodule then you just need to change your theme hook to be named mymodule_theme() . 如果名为mymodule则只需将主题挂钩更改为mymodule_theme() All Drupal hooks are MODULENAME_HOOKNAME(), if your module is called mymodule Drupal will be expecting to look for a theme hook function called mymodule_theme() . 所有Drupal挂钩都为MODULENAME_HOOKNAME(),如果您的模块名为mymodule Drupal将期待寻找一个名为mymodule_theme()的主题挂钩函数。

The simplest test is to put the line drupal_set_message('test'); 最简单的测试是在行drupal_set_message('test'); as the first line of your theme hook function and clear your caches. 作为主题挂钩函数的第一行,并清除缓存。 If you don't see the test message output to the screen, your hook function hasn't run, and it isn't named correctly. 如果您没有在屏幕上看到test消息输出,则说明您的挂钩函数未运行,并且命名不正确。

If you do see the test message and it still doesn't work I'd suggest it indicates a problem somewhere else, the rest of your code looks spot on. 如果您确实看到了test消息,但仍然无法正常工作,我建议它表明其他地方存在问题,其余的代码就可以找到。

EDIT I just noticed in a comment you're using a template file...I think there's some confusion as to do so you'd need to have the template key in the array returned from hook_theme() . 编辑我刚刚在评论中注意到您正在使用模板文件...我认为这样做有些混乱,因此您需要从hook_theme()返回的数组中包含template密钥。 Could you just clarify that? 您能澄清一下吗?

我在您的代码中没有看到任何问题(我没有测试过),但是您确定您已经清除了缓存...请清除缓存并告诉我此问题是否仍然存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM