This is one of the cases, I needed to change the layout of node add form. This snippet shows us how to theme one node type add form. Originally I inspired the solution from Development Seed's theme, rubik.
Let's suppose our node type is "TYPE", and theme name is "custom_theme". The template page is located in themes/custom_theme/templates/node-TYPE-form.tpl.php
.
First of all, define hook_theme() in your theme's template.php
.
/**
* Implementation of hook_theme().
*
*/
function custom_theme_theme() {
$items = array();
$items['TYPE_node_form'] = array(
'arguments' => array('form' => array()),
'path' => drupal_get_path('theme', 'custom_theme') . '/templates',
'template' => 'node-TYPE-form',
'preprocess functions' => array(
'custom_theme_preprocess_TYPE_form'
)
);
return $items;
}// end function custom_theme_theme;
Now implement the preprocess handler. We want to divide the form into two columns, main form in left sidebar, and taxonomy in right sidebar. As footer We will print the buttons.
function custom_theme_preprocess_TYPE_form(&$vars) {
// Copy taxonomy and buttons from $form to $vars, to pass them to the template file.
$vars['sidebar'] = $vars['form']['taxonomy'];
$vars['buttons'] = $vars['form']['buttons'];
// Remove taxonomy and buttons, from $form ( no duplication ).
unset($vars['form']['taxonomy']);
unset($vars['form']['buttons']);
}// end function custom_theme_preprocess_project_form;
After that, create the template page, where you will use drupal_render() function.
In or case the template page will be: themes/custom_theme/templates/node-TYPE-form.tpl.php
. And its code :
<div class="node-add-wrapper clear-block">
<div class="node-column-sidebar">
<?php if($sidebar): ?>
<?php print drupal_render($sidebar); ?>
<?php endif; ?>
</div>
<div class="node-column-main">
<?php if($form): ?>
<?php print drupal_render($form); ?>
<?php endif; ?>
<?php if($buttons): ?>
<div class="node-buttons">
<?php print drupal_render($buttons); ?>
</div>
<?php endif; ?>
</div>
<div class="clear"></div>
</div>
Finally, create your own CSS styling :)
A useful module, that might be alternative: Node form columns.
Also the whole procedure can be done using ctools Page Manager and Panels.
Comments
define hook_theme() in your
define hook_theme() in your theme's template.php *