如何在 Drupal 7 中将块插入节点或模板? [英] How to insert a block into a node or template in Drupal 7?
本文介绍了如何在 Drupal 7 中将块插入节点或模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Drupal 6 中,可以很容易地使用以下代码将块插入到模板中:
In Drupal 6, it was easy to insert a block into a template with the following code:
$block = module_invoke('views', 'block', 'view', 'block_name');
print $block['content'];
然而,在 Drupal 7 中使用相同的指令似乎不起作用.我环顾四周,找不到新方法.
However, using the same instructions in Drupal 7 does not seem to work. I have looked around and cannot find the new method.
Drupal 7 是否有允许以编程方式将块插入模板或节点的例程?
Does Drupal 7 have a routine that can allow for programmatically inserting a block into a template or node?
推荐答案
根据 wrburgess 的回答,如果您的服务器使用的是较新版本的 PHP,您可能会收到错误消息.
With wrburgess's answer you may get an error if your server is using a newer version of PHP.
Strict warning: Only variables should be passed by reference in include()...
我这样做是为了不引起/消除错误.
This is what I did to not cause/get rid of the error.
<?php
$blockObject = block_load('views', 'block_name');
$block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
$output = drupal_render($block);
print $output;
?>
这篇关于如何在 Drupal 7 中将块插入节点或模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文