You are here

function contemplate_preprocess_node in Content Templates (Contemplate) 7

Implements tempalte_prerocess_node().

because hook_nodeapi('alter') is no longer here I decided to change the node at just before the template gets invoked

File

./contemplate.module, line 965
Create templates to customize teaser and body content.

Code

function contemplate_preprocess_node(&$vars) {
  $node = $vars['node'];
  $node_type = node_type_get_type($node);
  $xml_elements = array();
  if ($template = contemplate_get_template($node_type->type)) {
    switch ($vars['view_mode']) {
      case 'teaser':
        if (CONTEMPLATE_TEASER_ENABLED & $template['flags'] && trim($template['teaser'])) {

          // only if there's content in teaser field
          $node->build = node_view($node, 'teaser');
          $teaser = contemplate_eval($template['teaser'], $node, $xml_elements);

          // because we are using the template we need to remove everything else
          // from the content array except the comments and the links, then
          // replace the body
          if (isset($vars['content']['comments'])) {
            $comments = $vars['content']['comments'];
          }
          else {
            $comments = FALSE;
          }
          $vars['content']['body'][0]['#markup'] = $teaser;
          $vars['content'] = array(
            'body' => $vars['content']['body'],
            'links' => $vars['content']['links'],
          );
          if ($comments) {
            $vars['content']['comments'] = $comments;
          }
        }
        break;
      case 'full':
        if (CONTEMPLATE_BODY_ENABLED & $template['flags'] && trim($template['body'])) {

          // only if there's content in the body field
          $node->build = node_view($node, 'full');
          $body = contemplate_eval($template['body'], $node, $xml_elements);

          // because we are using the template we need to remove everything else
          // from the content array except the comments and the links, then
          // replace the body
          if (isset($vars['content']['comments'])) {
            $comments = $vars['content']['comments'];
          }
          else {
            $comments = FALSE;
          }
          $vars['content']['body'][0]['#markup'] = $body;
          $vars['content'] = array(
            'body' => $vars['content']['body'],
            'links' => $vars['content']['links'],
          );
          if ($comments) {
            $vars['content']['comments'] = $comments;
          }
        }
        break;
    }
  }
}