2

I have a content type 'leg' and a template node--leg.tpl.php.
I'm using sky theme. I have a custom module as well, let's say for example, mymodule.
I put the template file into sites/all/modules/mymodule/theme. And I created a hook_theme and hook_preprocess_node.
But my template is not invoked as expected. I cleared all caches.

function mymodule_theme(){
    // The base theme registers node.tpl.php.
    $templates['node'] = array(
        'arguments' => array('elements' => NULL),
        'path' => drupal_get_path('module', 'mymodule') . '/theme',
        'template' => 'node--leg',
        'preprocess functions' => array(
          'template_preprocess',
          'mymodule_preprocess',
          'mymodule_preprocess_node',
          'mymodule_process',
        ),
    );
    return $templates;
}

function mymodule_preprocess_node(&$vars, $hooks){
    if($vars['type'] == 'leg'){

    }
}

When I put my template file into sites/all/themes/sky/templates and changed path in hook_theme to that location, it works.

function mymodule_theme(){
    // The base theme registers node.tpl.php.
    $templates['node'] = array(
        'arguments' => array('elements' => NULL),
        'path' => drupal_get_path('theme', 'sky') . '/templates',
        'template' => 'node--leg',
        'preprocess functions' => array(
          'template_preprocess',
          'mymodule_preprocess',
          'mymodule_preprocess_node',
          'mymodule_process',
        ),
    );
    return $templates;
}

I would like to know it is a right way or not.
I should not place my template in the sky theme folder, am I right ?

1

drupal_get_path('theme', 'mymodule') should be drupal_get_path('module', 'mymodule').

  • Sorry, it is typo error. – Sithu Jan 27 '12 at 11:22
  • 1
    Ah, no problem. Thought that it might be a very quick fix for you. Have you tried looking at some of the other contributed modules to see how they handle inclusion of templates? You shouldn't have to include the modules templates in a theme unless you were needing to override the module's default templates. – drmonkeyninja Jan 27 '12 at 11:49
  • I have tried several ways, but I failed. I think we cannot override the templates of the default theme from our custom module. node--leg.tpl.php in sky theme is invoked automatically without hook_theme(). When I tried hook_theme_registry_alter(), my template is called, but no variable is not passed to it. – Sithu Jan 30 '12 at 3:21
0

I resolved this by following :

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.