I am trying to develope my site with the CivicSpace theme (Drupal 4.6.5, PHP 5.0.5) and I encountered a problem when I try previewing my posts that has a trimmed version (either because of the post is long enough or because I use the break delimiter). In short, in the Preview post page it wasn't displaying the teaser preview version and an empty block for the full body:

http://drupal.org/node/45085

After I opened the issue, I found some free time and come up with a solution which works almost as expected. Can someone with better understanding of Drupal's inner works check my solution quickly and comment on its soundness please?

Here is the problematic function from the template.php of CivicSpace (it uses PHPTemplate Engine):

function phptemplate_node_preview($node) {
  if ($node->body) {
    if ($node->teaser && $node->teaser != $node->body) {
      $output .= '<h3>'. t('Preview trimmed version') .'</h3>' ."\n";
      $output = '<div class="preview preview-teaser">' ."\n";
      $output .= node_view($node, 1, FALSE, 0);
      $output .= "</div>\n";
      $output .= '<p><em>'. t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication. You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.') .'</em></p>' ."\n";
      $output .= '<h3>'. t('Preview full version') .'</h3>' ."\n";
      $output = '<div class="preview preview-full">' ."\n";
      $output .= node_view($node, 0, FALSE, 0);
      $output .= "</div>\n";
    }
    else {
      $output = '<div class="preview">' ."\n";
      $output .= node_view($node, 0, FALSE, 0);
      $output .= "</div>\n";
    }
   // rest is not very relevant so I am cutting here

and here is how I changed it :

function phptemplate_node_preview($node) {
  if ($node->body) {
    if ($node->teaser && $node->teaser != $node->body) {
      $node2 = clone($node);  // added line
      $output .= '<h3>'. t('Preview trimmed version') .'</h3>' ."\n";
      $output .= '<div class="preview preview-teaser">' ."\n";   // added .
      $output .= node_view($node, 1, FALSE, 0);
      $output .= "</div>\n";
      $output .= '<p><em>'. t('The trimmed version of your post shows what your
post looks like when promoted to the main page or when exported for syndication. You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.') .'</em></p>' ."\n";
      $output .= '<h3>'. t('Preview full version') .'</h3>' ."\n";
      $output .= '<div class="preview preview-full">' ."\n";  // added .
      $output .= node_view($node2, 0, FALSE, 0);  // changed line
      $output .= "</div>\n";
    }
    else {
      $output = '<div class="preview">' ."\n";
      $output .= node_view($node, 0, FALSE, 0);
      $output .= "</div>\n";
    }
    // cut

Not resetting $output made some progress but apparently node_view changes $node so I clone it for the second call. Is that OK? When I preview now it looks almost OK but I don't know if I go ahead and create the node smt will be broken.
It is almost OK because now under the full version I am also seeing the "read the rest of the post" link. Is there a solution for this? In fact, I tried to test other themes and they seem to have the same problem (displaying trimmed OK, but full version's body as empty) on my system. So I am not sure whether this is my personal problem or a more general issue. If this is OK should I submit a patch to the issue I opened?

Thanks.

Here is node_view's definition:
http://drupaldocs.org/api/4.6/function/node_view

Comments

mbr-1’s picture

Hi,

just wanted to point out that this issue seems to have been addressed with an easy fix here. It's a one word fix, and it worked for me (using a variant of bluemarine/non-phptemplate theme).

All the best.

mbr

manObject’s picture

I have encountered the same problem. I think it's all to do with the fact that the cutoff point for the 'trimmed version' sometimes occurs INSIDE an HTML tag rather than outside. The worst scenario is if you are using a theme that is built from HTML tables and the content of the trimmed also contains a table but the bottom end of the table is somewhere beyond the end of the trimming point! This results in a malformed table that will either display incorrectly or even crash your browser.

Does anyone know of a module that allows authors to submit separate content for the 'teaser'? This is a safer way of doing things and is used by many other Content Management Systems. Not only does it avoid the risk of this kind of mangling, it allows the author to provide a different, more compact form of words that can then optionally be inserted as an opening paragraph for the full version, or only used for those occasions where a brief precis is required.

I know that you should try to use CSS rather than tables, etc in postings, but what about legacy content? Items such as articles, pages and books? Such items often involve a complex tabular layout that is much easier to achieve using tables rather than divs and spans. Even if divs and spans are used exclusively, there is still the possibility of trim-mangling by omitting the bottom half of a long div, for example.

pembeci’s picture

Does anyone know of a module that allows authors to submit separate content for the 'teaser'?

You can check the Node Teaser module.

manObject’s picture

Thanks for the info - just what I needed!