drupal 6 -----为什么theme()无法输出
我在mytheme template.php中放入的代码
function mytheme_theme(){
return array(
'mytheme_example' => 'example',
'argument' => array('myvar' => null),
);
}
我在node.tpl.php中放入的代码
<?php
$html = "";
$myvar = "hello,world";
$html .= theme('mytheme_example', myvar);
return $html;
?>
我在example.tpl.php中放入的代码
<div>
here is the <b><?php print myvar; ?></b>being created.
</div>
我已经清除了缓存,但是在节点文章的页面上,没有任何输出关于你好世界。
ps:我可以使用哪些文件hook_theme、template.php、模块文件。有什么文件可以使用这个钩子吗?
the code i put in the mytheme template.php
function mytheme_theme(){
return array(
'mytheme_example' => 'example',
'argument' => array('myvar' => null),
);
}
the code i put in the node.tpl.php
<?php
$html = "";
$myvar = "hello,world";
$html .= theme('mytheme_example', myvar);
return $html;
?>
the code i put into the example.tpl.php
<div>
here is the <b><?php print myvar; ?></b>being created.
</div>
i have cleared the cache,but on the node article's page, there is no any output about hello world.
ps:which files i can use the hook_theme, template.php, module file. are there any files i can use this hook?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您已在 template.php 中正确声明了 hook_theme,所以我认为这不是问题。
我确实发现了您的node.tpl.php 的语法问题,不应该是这样吗:
请注意,带有“myvar”(在hook_theme 中声明的变量)的关联数组作为键传入。
另一点,标准做法是将模板文件命名为与挂钩名称相同,因此我建议将模板命名为 mytheme-example.tpl.php。
请参阅 drupal.org 了解更多信息
It looks like you have declared your hook_theme correctly in template.php so I do not think this is the issue.
I did spot a syntax issue with your node.tpl.php, should it not be:
Note the associate array, with the 'myvar' (the variable declared in hook_theme), is being passed in as the key.
Another point, it is standard practice to name the template file the same as the hook name, so I would suggest calling the template mytheme-example.tpl.php.
See drupal.org for more information
我不知道你是否已经解决了这个问题。
我会尝试这样声明我的主题:
这就是我通常所做的,而且对我来说效果很好。
I don't know if you have solved that issue yet.
I would try to declare my theme this way:
That's how I usually do and it works fine on me.