LeBlaireau
LeBlaireau

Reputation: 17467

Drupal using a template file for a block

I have the following structure in my module

- my module
  - templates
    mytemplate.tpl.php

and a block

function myblock_block_view($block_name = '') {
  if ($block_name == 'myblock') {



    return $block;
  }    
}

How do I use the tpl as the block content?

Upvotes: 0

Views: 24

Answers (1)

Amit
Amit

Reputation: 342

define a theme using hook_theme and specify path of your template in it as below

function hook_theme() {
  $theme = array(
    'custom_template' => array(
    'template' => '/templates/mytemplate',
  ));
  return $theme;
}

then in your hook_block_view do below

function myblock_block_view($block_name = '') {
  if ($block_name == 'myblock') {
    $block['content'] = theme('custom_template');
    return $block;
  }    
}

Upvotes: 2

Related Questions