1

I have a node type with machine name "resource", and I'm trying to theme it in my module "modulename".

I've tried doing this:

function modulename_theme() {
  return array(
    'resource_node_form' => array(
      'render element' => 'form',
      // 'template' => 'resource-node-form',
      // 'path' => drupal_get_path('module', 'modulename'),
    ),
  );
}

//I've tried both functions, getting nothing

function theme_resource_node_form($variables) {
  dsm($variables);
  return 'Testing';
}

function modulename_resource_node_form($variables) {
  dsm($variables);
  return 'Testing';
}

I've cleared cache, nothing happens. I've also tried with templating approach:

function modulename_theme() {
  return array(
    'resource_node_form' => array(
      //'render element' => 'form',
       'template' => 'resource-node-form',
       'path' => drupal_get_path('module', 'modulename'),
    ),
  );
}

And placing resource-node-form.tpl.php in modulename module folder. Cleared cache, nothing happens.

Sure I'm doing something wrong, but I can't figure it out. I've used templates for existing forms from a custom theme, but I'd like to do it this way, this time. Better approach for this project I'm working on, I think.

Thanks for your answers, ask me if you need more info!

2

Use this:

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
    // Expected format: NODE_TYPE_MACHINE_NAME_node_form
    case 'resource_node_form':
      // Requires devel module to be installed.
      // See all available elements displayed using krumo.
      $dpm($form);
      break;
  }

}

Update:

Depending on the complexity of your layout, check Display Suite and Field Group modules, as their functionality might be what you need.

You can also follow up this article if you want to do this from a tpl file. The approach is similar to what you were trying to do.

| improve this answer | |
  • Thanks for your answer, Topsitemakers! I've already done that to hide/show some fields, but I want to modify how the form gets printed. I want it to have two columns. – m0d Sep 28 '12 at 9:39
  • Answer updated. – Aram Boyajyan Sep 28 '12 at 10:09
  • Thanks Topsitemakers. I based my solution (the code I gave in my question) in that article, but it didn't work. Now I've tried again on a clean install, and it worked like a charm. So the error must be somewhere else in my site. If I find what's the problem, I'll come back here to comment. But I'll accept your answer, as it has worked on a clean install :) Thanks again. – m0d Sep 28 '12 at 11:37
  • Ok, in my hook_form_alter() I included a $form['#theme'] that created funny side effects. Thanks for all the answers! – m0d Sep 28 '12 at 11:53
1

Can you please try as following-

Go to your theme folder (used by your site) and create one new tpl file named as node-resource.tpl.php, then write your theming inside it.

May be it will help you.

For theming create node you can do as following-

node-resource-add.tpl.php

| improve this answer | |
  • Hello Ankur, thanks for your answer! But wouldn't that be a template for the node? I want to theme the form that creates that node. – m0d Sep 28 '12 at 9:36
  • Check my updated answer. – Ankur Jain Sep 28 '12 at 10:43

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.