1

I want to add a small html within the body tag of the site. I believe I can use template preprocess for this. I don't want to touch the template files. I am doing this from a module.

1
  • Is there a particular reason why you don't want to touch the page.tpl.php? If you mind about changing the original theme you can create a subtheme.
    – BetaRide
    Mar 25 '12 at 6:55
3

You should add hook_node_view() into your module. See the given example on how to add HTML markup.

function mymodule_node_view($node, $view_mode, $langcode) {
  $node->content['my_additional_field'] = array(
    '#markup' => $additional_field, 
    '#weight' => 10, 
    '#theme' => 'mymodule_my_additional_field',
  );
}
1

You can use hook_preprocess_page() for that:

MODULENAME_preprocess_page(&$vars) {
  // …
}    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.