Theme node body with a template file in the feature

Theme node body with a template file in the feature

This code can be used to add tpl.php files instead of implementing theme functions to your feature

  1. <?php
  2.  
  3. /**
  4. * Implementation of hook_theme().
  5. * DRUPAL WONT SEE THIS HOOK UNTIL YOU CLEAR YOUR CACHE
  6. */
  7.  
  8.  
  9. //Create myfeature-node-body.tpl.php in your feature and use $node to theme the node body
  10.  
  11. function myfeature_theme() {
  12.   return array(
  13.     'myfeature-node-body' => array(
  14.       'template' => 'myfeature-node-body',
  15.       'arguments' => array('node' => null),
  16.     ),
  17.   );
  18. }
  19.  
  20. /**
  21.  * Implementation of hook_nodeapi().
  22.  */
  23. function myfeature_nodeapi(&$node, $op, $a3, $a4) {
  24.   if ($node->type == 'mytype') {
  25.     switch($op) {
  26.       case 'view':
  27.         $node->content['body'] = array(
  28.           '#value' => theme('myfeature-node-body', $node),
  29.           '#weight' => 10,
  30.         );
  31.         break;
  32.       case 'load':
  33.         //add any extra data your template needs to $node here
  34.         break;
  35.     }
  36.   }
  37. }