You are here
hook_node_view (D7)
Seems basic but the part that is not in black and white when searching this hook is how to set up the theme render element.
Below is about all the help I could find, but looking into the field.module I was able to figure out how to make a theme function for my custom element.
<?php
function hook_node_view($node, $view_mode, $langcode) {
$node->content['my_additional_field'] = array(
'#markup' => $additional_field,
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
);
}
?>
To continue with the example provided lets add in the theme hook.
<?php
function hook_theme() {
$theme = array(
'mymodule_my_additional_field' => array(
'render element' => 'element',
),
return $theme;
}
?>
<?php
function mymodule_my_additional_field($element) {
$output = '<div class="field">';
$output .= '<div class="field-label">'. $element['element']['#title'] .'</div>';
$output .= '<div class="field-item even">'. $element['element']['#markup'] .'</div>';
$output .= '</div>';
return $output;
}
?>


Add new comment