Friday, March 29, 2024
HomeDeveloperTheming Node Form into Regions in Drupal 6

Theming Node Form into Regions in Drupal 6

Date:

Related stories

Join the Thriving Community: Getting Started with Slot Daftar on Mahadewa88

Introduction: Dive into the World of Slot Daftar Are you...

Hold’em Handbook: Essential Rules for Winning

Introduction Texas Hold'em is one of the most popular variants...

Laugh Out Loud: Embrace Happiness with Whimsical Amusement Dolls

Introduction: In a world that can sometimes feel weighed...

Elevate Your Game: Strategies for Using Matched Betting Calculators

In the world of betting, staying ahead of the...

Roulette Revelations: Understanding the Odds Behind the Wheel

Roulette, a classic game of chance, has long captivated...
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