I am creating a new module in drupal 7 called coolmodule and I'm trying to figure out how to bind content to the file sites/all/modules/coolmodule/coolmodule.tpl.php file. Here's the block view code in my coolmodule.module;

function coolmodule_block_view($delta = '') {

    $block['subject'] = t('My Special Module');

    $block['content'] = theme('coolmodule', array('myvar' => 'helloworld'));

    return $block;

But for some reason, pages with this block does not render sites/all/modules/coolmodule/coolmodule.tpl.php. What am I doing wrong?

1 Answer 1


you are missing a hook_theme() function

see you defined a theme for your block by using:

$block['content'] = theme('coolmodule', array('myvar' => 'helloworld'));

but you never told it how to relate your theme with the template file, this work is done in hook_theme() function.

function coolmodule_theme() {
    $items['coolmodule'] = array(
        'template' => 'coolmodule',   // here comes your template name
        'render element' => 'content'

    return $items;

Don't forget to clear your cache


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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