4.6.x node.module theme_node_preview($node)
4.7.x node.module theme_node_preview($node)
5.x node.module theme_node_preview($node)
6.x node.pages.inc theme_node_preview($node)
7.x node.pages.inc theme_node_preview($variables)

Returns HTML for a node preview for display during node creation and editing.


$variables: An associative array containing:

  • node: The node object which is being previewed.

See also


Related topics

1 theme call to theme_node_preview()
node_preview in modules/node/node.pages.inc
Generates a node preview.


modules/node/node.pages.inc, line 422
Page callbacks for adding, editing, deleting, and revisions management for content.


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;


Matt-H’s picture

I just noticed that the $preview_trimmed_version = FALSE; line doesn't seem to be doing anything. It was used in the D6 version, so I'm guessing that it is just a line of legacy code that could now be removed.

inventlogic’s picture

You can override this theme function by adding the following to your themes template.php

   *Output customized node preview on node edit and add forms.
   * @return
   * This just outputs the Full node ignoring the teaser mode.
  function Forums_Zen_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;
atomicreach’s picture

Can I edit this function via a Module ? If yes, how? If no, then what can I do to add my html on preview screen via module ?