Hello, I have my own module gismeteo.module and an implementing of hook theme:

/**
 * Implementation of hook_theme() in gismeteo.module file
 */
function gismeteo_theme() {
    $path = drupal_get_path('module', 'gismeteo') .'/theme';
    require_once "./$path/theme.inc";
    
    return array(
        'gismeteo_city_list_form' => array(
            'template' => 'gismeteo-city-list-form',
            'file' => 'theme.inc',
            'path' => $path,
            'arguments' => array('form' => NULL),
        ),
        'gismeteo_block_data' => array(
            'template' => 'gismeteo',
            'arguments' => array('cities' => NULL),
        )
    );
}

in gismeteo module directory i have a template file gismeteo.tpl.php. Help me, i cannot override it with gismeteo.tpl.php in my default theme

Comments

nevets’s picture

How are you trying to invoke the template, you should be using theme('gismeteo_block_data'. ...);

Jenechka’s picture

/**
 * Implementation of hook_block().
 */
function gismeteo_block($op = 'list', $delta = 0) {
    if ($op == 'list') {
        $blocks[0]['info'] = t('Gismeteo');
        // Not worth caching.
        $blocks[0]['cache'] = BLOCK_NO_CACHE;
        return $blocks;
    }
    else if ($op == 'view' && user_access('gismeteo content')) {
        $block['subject'] = t('Meteo');
        $block['content'] = theme('gismeteo_block_data', gismeteo_block_data());
        return $block;
    }
}
nevets’s picture

Thinks to do/check

a) Have you cleared the theme registry?

b) Does the user have the permission 'gismeteo content' (or are they user 1)?

c) Does gismeteo_block_data() return anything?

d) If you place a string in gismeteo.tpl.php does it show up?

Jenechka’s picture

a) Yes, many times (and drupal cache too)

b) I am an admin

c) yes

d) Yes, but only if i put it in tpl file that is in my gismeteo module folder

Module works great, the problem is that drupal doesn't want to use my theme overriding gismeteo.tpl.php file.
Devel module shows:
Files used: /sites/all/modules/gismeteo/gismeteo.tpl.php
Candidate: gismeteo.tpl.php

Candidate exists, but isn't in use.

mooffie’s picture

'gismeteo_block_data' => array(
'template' => 'gismeteo',
'arguments' => array('cities' => NULL),
)

i cannot override it with gismeteo.tpl.php in my default theme

In your theme folder you must name it "gismeteo-block-data.tpl.php", not "gismeteo.tpl.php".

Of course, the sane thing would be for you to change 'template' => 'gismeteo' to 'template' => 'gismeteo-block-data' as well. However, by doing this you'll lose the "element of surprise" over your enemies (enemies = the users of your module) because then they won't have any problems using and theming your module.

require_once "./$path/theme.inc";

This line serves nothing.

Jenechka’s picture

Oh, my god! Thank you very much! It works. All my pains are behind now.

sumanthkumarc’s picture

Thanks. The above template naming works for me too to override template from contrib module in my theme folder!!