Drupal 自定义模块 |如何输出块中节点的所有字段
我有一个节点,我想在块中输出,因为该节点可以包含不同类型的字段,我不想指定这些字段。
有人可以解释一下如何做到这一点吗?
我尝试了这个,但我只得到一长串通知,没有任何输出。
function mymodule_block_view($delta = '') {
$node = node_load(6);
$node_content = node_view($node);
switch($delta){
case 'mymodule':
$block['subject'] = t('title');
$block['content'] = theme('block', $node_content);
}
return $block;
}
提前致谢! 结果:无内容和通知列表:
*Notice: Undefined index: #block in template_preprocess_block() (line 937 of /home/user/public_html/drupal/modules/block/block.module).
Notice: Trying to get property of non-object in template_preprocess_block() (line 939 of /home/user/public_html/drupal/modules/block/block.module).
Notice: Trying to get property of non-object in template_preprocess_block() (line 940 of /home/user/public_html/drupal/modules/block/block.module).
Notice: Trying to get property of non-object in template_preprocess_block() (line 943 of*
I have a node that I want to output in a block, because the node can contain different kind of fields I don't want to specify the fields.
Can someone explain me how this can be done?
I tried this, but I just get a long list of notices without any output.
function mymodule_block_view($delta = '') {
$node = node_load(6);
$node_content = node_view($node);
switch($delta){
case 'mymodule':
$block['subject'] = t('title');
$block['content'] = theme('block', $node_content);
}
return $block;
}
Thanks in advance!
Result: No content and a list of notices:
*Notice: Undefined index: #block in template_preprocess_block() (line 937 of /home/user/public_html/drupal/modules/block/block.module).
Notice: Trying to get property of non-object in template_preprocess_block() (line 939 of /home/user/public_html/drupal/modules/block/block.module).
Notice: Trying to get property of non-object in template_preprocess_block() (line 940 of /home/user/public_html/drupal/modules/block/block.module).
Notice: Trying to get property of non-object in template_preprocess_block() (line 943 of*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我使用钩子节点时,我得到了结果。
在发布这个问题之前我已经测试了钩子节点,但是,是的,我不知道为什么它当时不起作用。
不知道这种方式是否是最好/最简单的方法,但我得到了输出,所以我很高兴!
无论如何,谢谢!
I've got a result when I use the hook node.
I already tested the hook node before posting this question, but yeah, i don't know why it wasn't working then.
Don't know if this manner is the best/easiest way but I've got an output so I'm glad!
Thanks anyway!
您有两个问题:
1)node_view() 返回一个需要使用 drupal_render()
2) 您不需要在此内容上使用 theme('block')。
如果您想将节点的对象传递给
tepmlate_preprocess_block
和匹配的theme
文件,您可以使用此文件然后,您可以在您的主题文件,通过访问 $block['#node']。
You have two problems:
1) node_view() returns an array which needs to be rendered using drupal_render()
2) You don't need to use theme('block') on this content.
If you want to pass the node's object to your
tepmlate_preprocess_block
and to your matchingtheme
file, you can use thisThen, you can use whatever attribute of the node you want in your theming file, by accesing $block['#node'].