1

How do I theme a CCK input form? I tried the approach given in this page, but it is not working even after I clear the cache. Here are the steps.

Suppose your content-type is: "account_registration" and you theme is "bluemarine".

I edited template.php and added this code:

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

I created node-account_registration-edit.tpl.php:

<?php
  $form['buttons']['submit']['#value'] = 'Done';
  $form['buttons']['preview']['#access']= FALSE;
?>

I cleared cache and edited a node, but the above changes are not showing up.

  • Can you please paste here an example of what you have done so far? Have you tried doing a dpm() or error_log() on your custom theme override to see if it's getting called? – amateur barista Apr 13 '11 at 18:59
2

Your steps are right. I tested it on my local environment, and it works.

For example, for the content type "companynews", add the function to the template.php:

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

Create the node-companynews-edit.tpl.php file and put the test code.

<?php
  echo 'it works!";
?>

Clear the cache, and access http://example.com/node/add/companynews: it shows "it works."

PS: You can also use hook_form_alter() to alter the form, and then use CSS to style it.

1

The reason the code is not working is that a template file is supposed to render the form fields, not to alter the $form array.
I would not suggest to use a template file for a form, and I would instead use a theme function.

As example of theme function used to render a form, look at the code of theme_node_filter_form(), which renders the node filter fields that appear in http://example.com/admin/content/node/overview.

function theme_node_filter_form($form) {
  $output = '';
  $output .= '<div id="node-admin-filter">';
  $output .= drupal_render($form['filters']);
  $output .= '</div>';
  $output .= drupal_render($form);
  return $output;
}

Drupal core modules don't use a template file for rendering a form, and you would not find examples of template files used in such way looking on api.drupal.org.

0

To find the appropriate theme or template name to overrride formatting the theme developer moduld is very handy. You can just point and click on whatever you like to change and it tells you what part of drupal is doing the rendering and all the possibilties to override and adjust it to your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.