I would like to remove the trimmed version from node preview. I can set the length of trimmed posts to Unlimited and that will remove the trimmed version everywhere... but I would like to remove it only from Preview... Thank you

Comments

cvining’s picture

I need this as well. Any ideas?

Louis Bob’s picture

in modules/node/node.pages.inc, starting line 388:

/**DISABLE CODE FROM HERE...
  // Do we need to preview trimmed version of post as well as full version?
  if ($trimmed != $full) {
    drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
    $output .= '<h3>' . t('Preview trimmed version') . '</h3>';
    $output .= $trimmed;
    $output .= '<h3>' . t('Preview full version') . '</h3>';
    $output .= $full;
  }
  else {

    $output .= $full;
}
 ... UNTIL HERE */

// write back the following line:
    $output .= $full;

Ugly solution I admit, but it works, and I've searched for too long for a solution for myself without sucess so far...

chrsnlsn’s picture

I managed to do this with the following function in my template.php remember change 'theme' to your theme name. I commented out the sections that deal with the teaser. you could also do this on a per content type basis using the $node variables available here.

/**
 * Override node preview to remove trimmed teaser version.
 */
function theme_node_preview($variables) {
  $node = $variables['node'];

  $output = '<div class="preview">';

  $preview_trimmed_version = FALSE;

  $elements = node_view(clone $node, 'teaser');
  $trimmed = drupal_render($elements);
  $elements = node_view($node, 'full');
  $full = drupal_render($elements);

  // Do we need to preview trimmed version of post as well as full version?
  if ($trimmed != $full) {
   // drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
    //$output .= '<h3>' . t('Preview trimmed version') . '</h3>';
    //$output .= $trimmed;
    //$output .= '<h3>' . t('Preview full version') . '</h3>';
    $output .= $full;
  }
  else {
    $output .= $full;
  }
  $output .= "</div>\n";

  return $output;
}

web Kreator

jeuelc’s picture

Thanks ChrisNelson for the solution.

cheers!

mmaul’s picture

Works perfectly, thank you!

thirdender’s picture

Thanks, works great :-p

candelas’s picture

I was getting crazzy!!
if it doesnt work, maybe it is because you need to empty the cache!!
@ChrisNelson thanks a lot! :)

//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong

jdln’s picture

Is this for Drupal 7? Its not working for me. Thanks

b3nji’s picture

Works in Drupal 7. You need to Clear all caches as stated above.

jdln’s picture

Still not working for me. Ive updated all modules and core, flushed cache, changed the first line to function zen_node_preview($variables) { (im using the zen theme but without any sub themes). Have I missed anything? Thanks

jdln’s picture

Zenophile was playing up so I didnt bother to create a zen sub theme. After creating a sub theme the code works fine.

jdln’s picture

Stopped working again! It seems this code doenst play nice with zen.

jdln’s picture

Will leaving the line $node = $variables['node']; as it is work for all content types or do you need to specify the content type? Thanks

jdln’s picture

This code now working.

http://drupal.org/node/1782016

edutrul’s picture

It works great!, thanks
If this is not working then check if you are using admin theme for content management. YOURTHEMENAME_preview()

1st Drupal 8 backend specialist acquia certified in Perú!
CTO / Software Architect / Senior Developer

inventlogic’s picture

Following is my shortened version to just output the full node as a preview which I've tested in template.php and works.

If your going to hack it why not reduce it as well?

If there are any reason why cutting out the unused code is a bad idea someone let me know please.

/**
 * Output customized node preview on node edit and add forms.
 */
function MYTHEME_node_preview($variables) {
  $node = $variables['node'];
  $elements = node_view($node, 'full');
  $full = drupal_render($elements);
  $output = '<div class="preview">';
  $output .= '<h3 class="post-preview" >' . t('Preview of your posting') . '</h3>';
  $output .= $full;
  $output .= "</div>\n";
  return $output;
}
CMStom’s picture

invent logic, Worked like a charm!

Thomas Newman
UI Developer
https://cmstom.com

stephesk8s’s picture

Worked perfectly. Thanks for posting, inventlogic.

markusd1984’s picture

Works great, thanks! Can we also change for the title to show the updated title?

For me, it's just showing "Preview".

potassiumchloride’s picture

code from chrsnlsn
This worked for me. For folks who may not be familiar with the template.php file, here are some things you might need to know:

1. If you're using a sub-theme, go to the template.php file inside your sub-theme folder. This is found in /sites/all/themes/[your-theme]/
2. Add the code to the "page template" part of the template.php file, not the "html template" or "node template." For a Corolla sub-theme, it goes in the section labeled "Override or insert variables for the page templates."
3. Verify that you have changed the first line to use your theme name, such as: function YOUR_THEME_node_preview($variables) {
4. Make sure you clear the cache before you test.