views:

2580

answers:

4

I want to theme the template for edit or add a node for a specific content type.
For example, to theme all the content type forms I use the file page-node-{add|edit}.tpl.php (depending what I need to do add or edit).

But I didn't found the template name for a custom node type, for example Products.

I need to theme only for Products, but not for the other content types.

I've tried with page-node-edit-product.tpl.php and page-node-product-edit.tpl.php but no luck.

+8  A: 

Hmm. there may be a better way but what about a preprocess function.

I'm still really new to Drupal, so I could maybe something like[code may not work]:

<?php
function themeName_preprocess_page(&$vars, $hook) {
  if ((arg(0) == 'node') && (arg(1) == 'add' || arg(2) == 'product')) {
    $vars['template_files'][] =  'page-node-add-product';
  }
}
?>

be sure to clear cache and theme registry after making new preprocess functions.

easement
Leandro Ardissone
Sadi
A: 

I'm a drupal noob myself, but would something (might need a little more) like this work?

function phptemplate_node_form($form)
{
  switch ($form['#node']->type) {
    case 'product':
    return theme_render_template(path_to_theme().'/node-edit-product.tpl.php', array('form' => $form));
    default:
     return theme_node_form($form);
}
}
Detect
+1  A: 

This is what I think is the 'proper' way to do it.

From the node module:

$form['#theme'] = array($node->type .'_node_form', 'node_form');

So Drupal will try to theme 'product_node_form'

so you can create a module which implements this.

You will need to implement [hook_theme][1], and provide a function or template.

You may find that it is easier to use [hook_form_alter][2] to add some classes and normal CSS to change the appearance.

Jeremy French
Ah, but I want to use a complete different template rather than theme the form only.
Leandro Ardissone
Though you can do as you have posted, I'm not sure this is what the OP wants. This will only change the template for the actual form (which currently doesn't use any), this will not change the page template that's being used. From his examples is seems like this is what he wants.
googletorp
A: 

Hi. For me the same problem. Prompt where to insert a code:

<?php
function themeName_preprocess_page(&$vars, $hook) {
  if ((arg(0) == 'node') && (arg(1) == 'add' || arg(2) == 'product')) {
    $vars['template_files'][] =  'page-node-add-product';
  }
}
?>

It is entered in template.php or in page-node - {add|edit}-example.tpl.php?

gaintsev
In the second comparison there's an error it must be an }}?>Because it applies to any content 'add'.
Leandro Ardissone