Thursday, April 24, 2025
HomeBusinessTheming Node Form into Regions in Drupal 6

Theming Node Form into Regions in Drupal 6

Date:

Related stories

Pakgame Login Perks: Special Promotions for Active Members

Online gaming platforms are constantly evolving, offering a range...

Exploring Dubai’s Hidden Gems by Boat: A Guide to Off-the-Beaten-Path Locations

Dubai is widely recognized for its iconic landmarks like...

The Evolution of Gaming: From Land-Based to Online Slots

Gaming has undergone a remarkable transformation over the years,...

Drivalia Car Rental Gatwick Airport: Fast & Reliable Booking via All Deals Travel

Finding a reliable and cost-effective car rental service can...

How to Synchronize Your Performance with Vocal Backing Tracks

Using vocal backing tracks can significantly enhance your live...
spot_img

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.

<?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;
}
?>

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.

<?php
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']);
}
?>

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 :

  
    <?php if($sidebar): ?>
      <?php print drupal_render($sidebar); ?>
    <?php endif; ?>
  
  
    <?php if($form): ?>
      <?php print drupal_render($form); ?>
    <?php endif; ?>
    
    <?php if($buttons): ?>
      
        <?php print drupal_render($buttons); ?>
    
  <?php endif; ?>
  
  

Finally, create your own CSS styling 🙂

Latest stories

spot_img