Monday, April 15, 2024
HomeDeveloperTheming Node Form into Regions in Drupal 6

Theming Node Form into Regions in Drupal 6

Date:

Related stories

Unleash Your Luck: Togel Rakyat Slot Game Extravaganza

Introduction Welcome to the ultimate gaming experience where luck meets...

Placing Bets Stateside: A Guide to Online Casinos in the USA

In the ever-evolving landscape of online entertainment, online casinos...

KK Bandar’s Poker Paradise: Play, Win, Repeat

Poker has long been hailed as the quintessential card...

Your One-Stop Shop for Global Communication: Translation Companies in the UK

In an increasingly interconnected world, businesses are expanding their...

From Novice to Pro: Navigating Slot Gacor and Online Gaming Like a Champ

In the vast landscape of online gaming, mastering the...
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