0

I am creating a block and I cannot get it to render correctly. I need to render a list of links but it is not working and it is showing nothing on the page.

I have the hook_theme() function like this:

function list_city_theme() {
  return array(
    'list_city_display' => array(
      'variables' => array(
        'title' => NULL,
        'locations' => NULL
      ),
      'template' => 'filter-by-city--display.tpl.php',
    ),
  );
}

And heres where i'm trying to set the theme inside the block view function:

$args = array(
  'title' => 'Filter by Town / City',
  'locations' => $locations
);
$block['content'] = theme('list_city_display', $args);
0

It is working for me. I have created a module called testtheme and mytemplate.tpl.php file is under testtheme/templates/.

Please try following sample code

/**
 * Implements hook_block_info().
 */
function testtheme_block_info() {
  $blocks['testtheme'] = array(
    'info' => t('Test Theme'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function testtheme_block_view($delta=0) {
  $black = array();
  if ($delta == 'testtheme') {
    $block['subject'] = t('Test Theme');
    $args = array(
      'title' => 'Filter by Town / City',
      'locations' => 'Bangalore',
    );
    $block['content'] = theme('list_city_display', $args);
  }
  return $block;
}

/**
 * Implements hook_theme().
 */
function testtheme_theme() {
  $path = drupal_get_path('module', 'testtheme');
  return array(
    'list_city_display' => array(
      'variables' => array(
        'title' => NULL,
        'locations' => NULL
      ),
      'template' => 'mytemplate',
      'path' => $path . '/templates',
      'type' =>'theme',
    ),
  );
}
|improve this answer|||||
0

To View the contents in a block must be implemented hook_block_view

/**
 * Implements hook_block_view().
 *@param $delta
 */
function list_city_block_view($delta='') {
  $block = array();
  switch($delta) {
    case 'block_name' :      
      $block['content'] = theme('list_city_display', array('result' => array('title'=> NULL,'locations' => NULL)));
      break;  
  }
  return $block;
}
|improve this answer|||||

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.