0

I read this answer, but I can not figure out, why my block is not shown. My block is activated in footer and should appear on <front>.

/**
 * Implements hook_theme().
 */
function poll_dialog_theme() {
  return array(
    'poll_dialog_output' => array(
      'variables' => array(
        'title' => NULL,
        'content' => NULL,
        'popular_content' => NULL,
      ),
      'template' => 'theme/poll_dialog',
    ),
  );
}

function poll_dialog_block_info() {
  $blocks['poll_dialog'] = array(
    'info' => t('Poll Dialog'),
    'cache' => DRUPAL_NO_CACHE, //there are a number of caching options for this
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function poll_dialog_block_view($delta = '') {
  switch ($delta) {
    case 'poll_dialog':
      $block['subject'] = t('poll_dialog');
      $block['content'] = _poll_dialog_block_content();
      break;
  }
  return $block;
}

/**
 * Callback implemented by hook_block_view().
 */
function _poll_dialog_block_content() {
  $static_title = t('Static Title');
  $static_content = 'static content';

  return theme('poll_dialog', array(
      'title' => $static_title,
      'content' => $static_content,
      'link' => l('Poll', 'some url'), array('attributes' => array('target' => '_blank'))),
    )
  );
}

1 Answer 1

2

You're calling a non-existent theme function. Your code should be:

return theme('poll_dialog_output', array(
    'title' => $static_title,
    'content' => $static_content,
    'link' => l('Poll', 'some url'), array('attributes' => array('target' => '_blank'))),
  )
);

or, even better:

return array(
  '#theme' => 'poll_dialog_output',
  '#title' => $static_title,
  '#content' => $static_content,
  '#link' => l('Poll', 'some url'), array('attributes' => array('target' => '_blank'))),
);

The main point is that the name of the theme function you call needs to match what you've used in hook_theme().

2
  • Ah! That's the missing link. Good - xdebug shows that my theme file is loaded and parsed. But this block content is still not on my page. I put it into 'head' section and it's not restricted to any page - maybe I should open a new question.
    – Jurik
    Commented Aug 6, 2015 at 10:19
  • Yeah opening a new question for that would be good @Jurik
    – Clive
    Commented Aug 6, 2015 at 10:22

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