This post is all about summary styling in full node view.
I'm tring to style the summary differently from the body text.

The problem is that the php variable $node->teaser I would like to use in my node.tpl.php has already been destoyed for security purposes, using unset, by the node module.

Please could you help me in figuring out how include the teaser text ($node->teaser) in my node template (node.tpl.php), for display in node full view ?

Example of the result I'd like to obtain in full node view :

Summary summary summary summary,Summary summary summary summary. Summary summary summary summary. Summary summary summary summary,Summary summary summary summary.
Body text body text. Body text body text, body text body text. Body text body text body text body text body text body text body text. Body text body text. Body text body text, body text body text. Body text body text body text body text body text body text body text.

Here is the section of my node.tpl.php which is responsible for displaying either only the teaser on teaser views, or both the teaser and the body text in the full node view :


      <?php if ($teaser): /* in teaser view */ ?>
        <div class="node-summary">
          <?php echo $node->teaser; ?>
        </div>
      <?php else: /* in full view */ ?>
        <div class="content">
          <div class="node-summary"><?php echo $node->teaser; ?></div>
          <hr />
          <div class="node-body"><?php echo $node->body; ?></div>
        </div>
      <?php endif; ?> 

The problem is that out of $teaser, the $node->teaser; doesn't exist anymore, therefore I can't call it.

All what i want to do just works fine when I hack the core, precisely the node module, just by commenting out the line 1017. That way the function doesn't unset the $node->teaser variable.
File to be found in the core at this location :
mydrupalsite/modules/node/node.module
See the following code :

<?php 
/**
 * Generate a display of the given node.
 *
 * @param $node
 *   A node array or node object.
 * @param $teaser
 *   Whether to display the teaser only or the full form.
 * @param $page
 *   Whether the node is being displayed by itself as a page.
 * @param $links
 *   Whether or not to display node links. Links are omitted for node previews.
 *
 * @return
 *   An HTML representation of the themed node.
 */
function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
  $node = (object)$node;

  $node = node_build_content($node, $teaser, $page);

  if ($links) {
    $node->links = module_invoke_all('link', 'node', $node, $teaser);
    drupal_alter('link', $node->links, $node);
  }

  // Set the proper node part, then unset unused $node part so that a bad
  // theme can not open a security hole.
  $content = drupal_render($node->content);
  if ($teaser) {
    $node->teaser = $content;
    unset($node->body);
  }
  else {
    $node->body = $content;
    unset($node->teaser);      /*HERE*/   // unset destroys the $node->teaser variable 
  } 
?>

The problem is that I've read that it can cause xss issues, and that modifying the core makes it difficult to update drupal, and my code is not clean at all.

So is there a way using theme override functions in my template.php ?
For example, with function my_theme_node_view or function my_theme_nodeapi or function my_theme_preprocess_node ?

This problem has already been discussed here, but I can't get any of these to work :
http://www.disobey.com/node/1833

P.S. 1:
- As far as I know, the checkbox "Show summary in full view" is of no help for me, because, the teaser ($node->teaser) is simply added to the body text ($node->body) and merged into the content ($content). It works even better for me with my hack in node core module with this unchecked, otherwise, the teaser is displayed twice.

- It has to work either if the user uses a teaser breack or if the teaser is generated automatically by the node module.

P.S. 2:
Further hints :
I suspect this function in template.php to play a role in my expectations, but I can't figure out how I can use it.
I'm not sure that drupal takes into account the modifications i make in my template.php, and that worries me. I tried overriding but nothing appeared to change. Even when i have rebuilt the theme registry.
(my_theme name has got a _ inside it, Can this cause issues ?)

<?php 
function my_theme_preprocess_node(&$vars, $hook) {
  // Special classes for nodes
  $classes = array('node');
  if ($vars['sticky']) {
    $classes[] = 'sticky';
  }
  if (!$vars['status']) {
    $classes[] = 'node-unpublished';
    $vars['unpublished'] = TRUE;
  }
  else {
    $vars['unpublished'] = FALSE;
  }
  if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
    $classes[] = 'node-mine'; // Node is authored by current user.
  }
  if ($vars['teaser']) {
    $classes[] = 'node-teaser'; // Node is displayed as teaser.
  }
    
  }
  
  // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
  $classes[] = my_theme_id_safe('node-type-' . $vars['type']);
  $vars['classes'] = implode(' ', $classes); // Concatenate with spaces

}
?>

P.S. 3:
I'm developping my theme for drupal 6.13, based on basic theme, and my site is currently running with MAMP on MAC OS X 10.4. Every thing is fine with apache and Mysql.

It's my first post, I usually find what I seek for in the manuals and the forums. Hope I'm writing it correctly. Sorry for its lenght, but I had much things to explain, and I thought it would be easier for you to understand with bigger bits of the source code.

Thanks for your attention

Comments

Jerome F’s picture

Hi folks, if anyone is interrested in the answer,

I had to create a new field with cck called "Accroche introductive", the machine name is "field_accroche".
(I wanted it to be in french for my personnal comfort of use, but you might call it node lead or node intro or else, as you might wish...)
It is set in manage field with a wheight of -1 with a text type (make sure to activate text in cck module) and a textarea widget.
In display field, the label is hidden (i don't want it to be displayed, just the text) ; in teaser: plain text ; and in full node : hidden.
Then I display it in a separated div with a themable class thanks to node.tpl.php

Here is my final node.tpl.php:

<div class="node <?php echo $classes; ?>" id="node-<?php echo $node->nid; ?>">
	<div class="node-inner">
    
    <?php if ($page == 0): ?>
	    <h2 class="title node-title">
				<a href="<?php echo $node_url; ?>"><?php echo $title; ?></a>
			</h2>
    <?php endif; ?>    
    
    <?php if ($terms): ?>
      <div class="taxonomy"><?php echo $terms; ?></div>
    <?php endif;?>
    

	 <?php if ($teaser): /* in teaser view */ ?>
      
			 <?php if ($field_accroche): ?>
                  <div class="node-summary">
				  <p><?php echo $node->field_accroche[0]['value']; ?></p>
                  </div>
             <?php else: /* if no accroche is set, then use the teaser */ ?>
                  <div class="node-summary">
				  <?php echo $node->teaser; ?>
                  </div>
             <?php endif;?>    

      <?php else: /* in full view */ ?>
     	<div class="content">
		  <?php if ($node->field_accroche[0]['value'] == ''): ?>
          	
		  <?php elseif ($field_accroche): ?>
              <div class="node-intro"><?php echo $node->field_accroche[0]['value']; ?></div>
              <hr />
          <?php endif;?> 
         
          <div class="node-body"><?php echo $node->body; ?></div>
        </div><!-- end .content -->
      <?php endif; ?> 



    <?php if ($picture): ?>
	    <div class="picture"><?php echo $picture; ?></div>
	  <?php endif; ?>

    <?php if ($submitted): ?>
      <span class="submitted"><?php echo $submitted; ?></span>
    <?php endif; ?>
  	
    <?php if ($links): ?> 
	    <div class="links"> <?php echo $links; ?></div>
	  <?php endif; ?>
    
	</div> <!-- /node-inner -->
</div> <!-- /node-->

So if there is an introduction text (here called "accroche"), it will be used as teaser in teaser view and as the beginning of the text in node view, if there isn't the automaticly generated teaser or the one created using will be used for teaser view and nothing will appear in node view but the text. Then you're still free either to enable or to disable the checkbox "show teaser in fuull view", if you need to, because the introduction is now something completly different from the teaser (checked) / summary (unchecked).

Links where i found further documentation:
http://idcminnovations.com/article/drupal-pages-and-views-cck-computed-f...
http://www.drupaltherapy.com/
http://learnbythedrop.com/

The final effect can be seen in this very web site :
http://www.virginie-larcher-naturopathe.fr/