How to Theme Node Forms in Drupal 7



In Drupal 6, we create a separate template file for node/add/custom_content_type. This is done by writing a following function in template.php:

<?php
function mytheme_theme() {
return array(
'custom_content_type_node_form' => array(
'arguments' => array('form' => NULL),
'path' => drupal_get_path('theme''mytheme') . '/templates',
'template' => 'custom_content_type-node-form',
'render element' => NULL,
)
);
}
?>

Then you created my custom_content_type-node-form.tpl.php file.

In Drupal 7, path templates are built-in, so just do this:

<?php
page
--node--add--blog.tpl.php (for blog)
page--node--add--story.tpl.php (for story)
?>

Refresh cache!

PS Page template suggestions go into mytheme_preprocess_page(&vars), like this:
Drupal 7 example:


<?php
/**
* Implementation of hook_preprocess_page().
*/
function mytheme_preprocess_page(&$vars) {

  
// Node template suggestions like page--node--blog.tpl.php
  
if (isset($vars['node'])) {
     
$vars['theme_hook_suggestions'][] = 'page__node__' str_replace('_''--'$vars['node']->type);
  }

}
?>



Yea, this actually doesn't work with the Bartik theme.

I don't know what theme you're using but page--node--add--webform.tpl.php does no override the default node.tpl.php as a template suggestion.