hi
i am trying to add my tpl.php for node/add/content-type .i have done this thing in drupal 5 by use PHPtemplete function but it is not working in drupal 6
can any one help

Comments

Mark B’s picture

It depends how you want to do it.

I've written a custom module to support a new node type called "course" (for golf courses), and wanted part of the data entry form to be laid out as a table. There are two pieces to making this work:

  • your theming function
  • an implementation of hook_theme to tell the theming system about your theming function

I've written an implementation of hook_theme:

function course_theme($existing, $type, $theme, $path) {
  return array(
    'course_node_form' => array(
      'arguments' => array('form' => NULL),
    ),
  );
}

then the theming function itself:

function theme_course_node_form($form) {
  $output .= drupal_render($form['title']);
  
  // generate column headers
  $headers[] = array('data' => t('Hole'));
  $headers[] = array('data' => t('Length'));
  $headers[] = array('data' => t('Par'));
  
  for($hole=1; $hole<=9; $hole++) {
    $row['data'][0] = $hole;
    $row['data'][1] = drupal_render($form['holes'][$hole]['length']);
    $row['data'][2] = drupal_render($form['holes'][$hole]['par']);    
    $rows[] = $row;
  }
  
  $output .= theme('table', $headers, $rows); 
  $output .= drupal_render($form);
  
  return $output;
}

Checking the documentation on hook_theme, it looks as though you should be able to add a "template" element to the array in your hook_theme implementation to tell it to use a template file if that's more suited to your particular theming requirements:

function course_theme($existing, $type, $theme, $path) {
  return array(
    'course_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'node-course-edit',
    ),
  );
}

You would then need to create a node-course-edit.tpl.php file in your theme directory. I haven't tried this, so it may still be missing something, but it should at least get you on the right track.

dru_india’s picture

Thanks it worked

kinderpera’s picture

Is not working to me; I tried this very simple example in my template.php:

function mystyle_theme($existing, $type, $theme, $path) {
  return array(
    'mystyle_node_form' => array(
		'arguments' => array('form' => NULL),
    ),
  );
}

function theme_mystyle_node_form($form) {
	return "<h5>WORKS!</h5>";
}

what I'm doing wrong?

kinderpera’s picture

ok, if I set up a template it works:

(template.php)

function myadmintheme_theme(&$existing, $type, $theme, $path) {
  return array(
    'node_form' => array(
        'arguments' => array('form' => NULL),
        'template' => 'ccktype',
    ),
  );
}

(ccktype.tpl.php)

<h5>WORKS!</h5>
mcpuddin’s picture

For those that are trying this but are having issues or for some reason the 'code isn't work', make sure you clear your template cache.

Also, here is a good article that kind of spins off from this same discussion:
http://adaptivethemes.com/using-hook-theme-to-modify-drupal-forms

James McBryan
Founder & Technical Lead
Twomile - http://www.thetechscouts.com
"Technical Guides for Social Good"

mchaplin’s picture

To access the $form variables inside a template, you still need the theming function in the template.php even if its just

function theme_course_node_form($form) {
    return $form;
}
OptimusPrime23’s picture

Hi ,

I'm using themename_theme() in my template.php file to add custom node add form. But the same form get loaded for the node edit form as well. How can i used two different templates for node's add form and node's edit form?