对Drupal非常陌生。我试图添加一个简单的"你好世界"字符串drupal页面时,它使用hook_node_view加载。我的代码到目前为止:
function myModule_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full' && $node->type == 'page') {
$node->content['myText'] = array(
'#markup' => '<h1>HELLO WORLD</h1>',
);
}
}
根据我的理解,当页面加载时,每个节点将调用hook_node_view,如果节点类型是页面,则应该将我的hello world字符串添加到其文本的末尾。我确信这种理解是完全错误的,但我不确定从这里要去哪里。任何帮助都将非常感激。
最终,hello world将是动态内容,我希望它打印到每个drupal页面的顶部。
谢谢!
添加重量
function myModule_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full' && $node->type == 'page') {
$node->content['myText'] = array(
'#markup' => '<h1>HELLO WORLD</h1>',
'#weight' => -1 // negative will brings to the top
);
}
}