hook_theme() 不传递参数
我目前编写了一个生成块的模块。输出应该由模板定义。没什么特别的,但争论似乎没有得到正确的通过。
这是主题方法:
/* # Theme {{{*/
function browse_by_taxonomy_theme() {
return array(
'browse_by_taxonomy_block' => array(
'template' => 'browse_by_taxonomy_block',
'arguments' => array(
'next' => null,
'previous' => null,
'term' => null,
'hide_if_null' => variable_get('browse_by_taxonomy_hide_links', false)
)
)
);
}/*}}}*/
它的调用方式如下:
$block['content'] = theme('browse_by_taxonomy_block', "next", "previous", $tid);
即使我将其设置为最小值,它也不起作用:
function browse_by_taxonomy_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$block = array(array('info' => t("Browse by taxonomy")));
return $block;
case 'view':
# […] Dragons be here
return array(
'subject' => null,
'content' => theme('browse_by_taxonomy_block', "next", "previous", "p")
);
}
}/*}}}*/
但在我的模板中,一切都是null
var_dump($previous); # => NULL
var_dump($next); # => NULL
var_dump($hide_if_null); # => NULL
var_dump($term); # => NULL
在我编写的另一个模块中,我以几乎相同的方式完成了它并且它有效。这次我做错了什么?
I currently write a module that generates a block. The output should be defined by a template. Nothing special, yet the arguments don't seem to get passed properly.
This is the theme-method:
/* # Theme {{{*/
function browse_by_taxonomy_theme() {
return array(
'browse_by_taxonomy_block' => array(
'template' => 'browse_by_taxonomy_block',
'arguments' => array(
'next' => null,
'previous' => null,
'term' => null,
'hide_if_null' => variable_get('browse_by_taxonomy_hide_links', false)
)
)
);
}/*}}}*/
And it's being called like that:
$block['content'] = theme('browse_by_taxonomy_block', "next", "previous", $tid);
Even when i put it to the minimum of this it does not work:
function browse_by_taxonomy_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$block = array(array('info' => t("Browse by taxonomy")));
return $block;
case 'view':
# […] Dragons be here
return array(
'subject' => null,
'content' => theme('browse_by_taxonomy_block', "next", "previous", "p")
);
}
}/*}}}*/
But in my template everything is null
var_dump($previous); # => NULL
var_dump($next); # => NULL
var_dump($hide_if_null); # => NULL
var_dump($term); # => NULL
In another module i wrote i did it pretty much the same way and it works. What am I doning wrong this time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题很可能是由缓存问题引起的,因为 Drupal 出于性能原因缓存了所有主题信息。
Most likely the problem is caused by caching issues, as Drupal caches all theme info for performance reasons.
在这种情况下,缓存是魔鬼,我的朋友......只需刷新您的主题,它很可能会起作用。至少在我的情况下是这样的,经过长时间的搜索,充满了咒骂和咒骂,我终于尝试了,宾果......
Caching is the devil in this case my frend... just refresh your theme and it will most likely work. That was the thing in my case atleast, after a long long long search filled with lots of cursing and swearing I finally tried that and BINGO...