show preview and not all page/forms

by user3433303   Last Updated December 16, 2017 13:07 PM

I need to show only the preview and not all page and forms

I made a new window after clicking preview but I see ALL page (a duplicate) including header, footer and form compiled. I need to show the preview only.

function node_form_build_preview($form, &$form_state) {
  $node = node_form_submit_build_node($form, $form_state);
  $form_state['node_preview'] = node_preview($node);
}

can someone help?

Tags : entities 6


Answers 1


If you dont like what Drupal is doing by default for this preview feature, override it in your site theme, there is an example of this in the node_preview Drupal 7 API node_preview() comments.

the comment incorrectly titles the function THEME_Node_preview() it should all be lowercase

  /**
   *Output customized node preview on node edit and add forms.
   *
   * @return
   * This just outputs the Full node ignoring the teaser mode.
   */
  function YOURTHEME_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;
  }

If that still doesn't look right you could try altering this code further to:

  • provide an override to node.tpl.php or node--preview.tpl.php using theme suggestions for drupal's theming layer functions.
  • alter the results of $full above using Regular Expressions to hack off the beginning and end of the HTML page content.
tenken
tenken
March 18, 2014 15:43 PM

Related Questions




How to create a custom template for entities?

Updated April 07, 2015 03:03 AM


Drupal 8 Custom Entities from a UI?

Updated July 14, 2015 15:03 PM