Drupal → Как добавить контент к ноде перед её выводом
Drupal 7
Для модулей:
/** * Implements of hook_node_view(). */ function MODULENAME_node_view($node, $view_mode, $langcode) { if ($node->type == 'article' && $view_mode == 'full') { $node->content['mycontent'] = array( '#markup' => 'My node content', '#weight' => 10, ); } }
Для модулей и тем:
/** * Preprocess function for node.tpl.php */ function THEMENAME_preprocess_node(&$vars) { if ($vars['node']->type == 'article' && $vars['page']) { $vars['content']['mycontent'] = array( '#markup' => 'My node content', '#weight' => 10, ); } }
Ещё один вариант добавления контента с помощью псевдо-полей.
Drupal 6
Для модулей:
/** * Implements of hook_nodeapi(). */ function MODULENAME_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { if ($node->type == 'article' && $op == 'view' && $a4) { $node->content['mycontent'] = array( '#value' => 'My node content', '#weight' => 10, ); } }
Для модулей и тем:
/** * Preprocess function for node.tpl.php */ function THEMENAME_preprocess_node(&$vars) { if ($vars['node']->type == 'article' && $vars['page']) { $vars['content'] .= 'My node content'; } }
Оставить комментарий