1

I'm getting a really strange issue. I created a module that uses a template file:

/**
 * Implements hook_block_info().
 */
function emed_newsletter_block_info() {
  $blocks['newsletter_signup'] = array(
    'info' => t('Newsletter Signup'),
    'cache' => DRUPAL_NO_CACHE
  );

  return $blocks;
}
/**
 * Implements hook_block_view().
 */
function emed_newsletter_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'newsletter_signup':
      $block['subject'] = t('');
      $block['content'] = array(
        '#theme' => 'newsletter_signup'
        );
      break;
  }
  return $block;
}
/**
 * Implements hook_theme().
 */
function emed_newsletter_theme($existing, $type, $theme, $path) {
  return array(
    'newsletter_signup' => array(
      'render element' => 'content',
      'file' => 'templates/newsletter.tpl.php',
    ),
  );
}

The template file just contains HTML.

The problem is that the text/html inside the template is being printed on every page at the top. Even on a drush cc all

Has anyone run into this issue before?

Core Version = 7.24

  • hello and welcome. Your question shouldn't depend on external links. It should be valid even if external sites goes down. – Mołot Jan 8 '14 at 9:55
  • Good point! I didn't want to flood though. Thanks for correcting it for me – kevin.coyle Jan 8 '14 at 11:31
  • No need to be shy - short neat code like yours is perfect example of how to prepare code to be put into question. You aren't even near to cause flood! Module with thousands lines would be flood, but then one should trim it down, with the spirit of SSCCE in mind, like you apparently did. – Mołot Jan 8 '14 at 11:32
2

I'm pretty certain you want to be saying 'template' in your hook_theme():

template: If specified, this theme implementation is a template, and this is the template file without an extension. Do not put .tpl.php on this file; that extension will be added automatically by the default rendering engine (which is PHPTemplate). If 'path', above, is specified, the template should also be in this path.

instead of 'file', as...

file: The file the implementation resides in. This file will be included prior to the theme being rendered, to make sure that the function or preprocess function (as needed) is actually loaded; this makes it possible to split theme functions out into separate files quite easily.

...which would suggest the reason why all of this html is being spit out on top of each page because it is being included every time instead of being buffered with Drupal's theme engine as a template and then output later on.

  • Perfect that was my issue! :) – kevin.coyle Jan 8 '14 at 16:14
0

Hi Check whether you have configured your block for a specific pages in the block configuration

"admin/structure/block"

Block Configuration

  • That doesn't explain why it shows up on drush cc. Or on themes where that block isn't placed at all (like on the admin theme) – kevin.coyle Jan 8 '14 at 11:30

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.