Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I theme the template for edit or add a node for a specific content type?

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.

like image 916
Leandro Ardissone Avatar asked Oct 08 '09 15:10

Leandro Ardissone


People also ask

How do you add a page template for content types in Drupal 8?

To tell Drupal to use the page template for a content type, you can implement hook_theme_suggestions_page_alter() . This hook is used whenever a page. tpl. php template is used and allows you to suggest alternative templates.


2 Answers

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

I'm still really new to Drupal, so I would maybe try something like this [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.

like image 113
easement Avatar answered Sep 23 '22 21:09

easement


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.

like image 44
Jeremy French Avatar answered Sep 24 '22 21:09

Jeremy French