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

给你一囗甜甜゛ 提交于 2019-12-02 18:33:54
easement

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.

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.

function themename_preprocess_page(&$vars) { 
  // Add per content type pages
  if (isset($vars['node'])) {
    // Add template naming suggestion. It should alway use hyphens.
    // If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
    $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
  }
}

Add the above code in template.php

Then create couple of tpl files

1) page-contenttype.tpl.php

used when displaying and editing the content

2) page-node-add-contenttype.tpl.php

used when adding that content type.

Works with drupal 6.

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);
}
}

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?

Julie

I put this in my template.php file in my theme's directory:

function MYTHEMENAME_theme($existing, $type, $theme, $path) {
  return array(
    // tell Drupal what template to use for the edit form
    family_individual_node_form' => array(
        'arguments' => array('form' => NULL),
        'template' => 'node-family_individual-edit'
    )
  );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!