如何在Drupal 7中修改$ content数据?
我想更改/修改模块的块内容:博客
我尝试了我的template.php文件:
function blog_block_view($delta = '') {
return "Test, yes i am here";
}
但没有任何反应......
答案 0 :(得分:1)
要更改现有广告资源的$内容,您需要create a custom module,hook_block_view_alter
()实施。
Drupal.org示例:
function hook_block_view_alter(&$data, $block) {
// Remove the contextual links on all blocks that provide them.
if (is_array($data['content']) && isset($data['content']['#contextual_links'])) {
unset($data['content']['#contextual_links']);
}
// Add a theme wrapper function defined by the current module to all blocks
// provided by the "somemodule" module.
if (is_array($data['content']) && $block->module == 'somemodule') {
$data['content']['#theme_wrappers'][] = 'mymodule_special_block';
}
}
答案 1 :(得分:0)
根据以下示例,您可以在.module文件中进行修改。
function hook_block_view($delta = '') {
// All of these are functionally identical.
$block['subject'] = '';
$block['subject'] = NULL; // Or just don't set.
$block['title'] = '<none>'; // Undocumented, but works.
// This will not behave as desired.
$block['subject'] = '<none>';
$block['content'] = array(
'#theme' => 'feed_icon',
'#url' => 'rss.xml',
'#title' => t('Syndicate'),
);
return $block;
}
答案 2 :(得分:0)
这是正确的格式。
确保检查增量是否正确,否则您可能会更改比您的意图更多的块。
/**
* Implements hook_block_view().
*/
function mycustom_module_block_view($delta = '') {
if ($delta == "mydelta"){
$block['subject'] = 'The Greatest Block Ever Created';
$block['content'] = array(
'#markup' => "<h1>Here's some content</h1>",
);
}
return $block;
}