Hi all,

I've created a preprocess_block function in my theme template.php file. Devel themer is showing the custom block suggestion and I've created a template file using that name. However, Drupal is simply ignoring the file entirely. I created a duplicate of block.tpl.php in my theme and yet Drupal seems to pick that up without a problem.

Is there any reason why this would be occurring? My code is as follows:

function mytheme_preprocess_block(&$variables) {
    $block = $variables['block'];
    if ($block->module == 'webform') {
        // kpr($variables);
        $delta = explode('-', $block->delta);
        foreach ($delta as $k => $v) {
            if (is_numeric($v)) {
                $wrapper = entity_metadata_wrapper('node', $v);
                $machine_name = $wrapper->field_machine_name->value()['machine'];
                $variables['theme_hook_suggestions'][] = 'block__webform_' . $machine_name;
            }
        }
    }
}

Thanks in advance,

welly

Comments

Jaypan’s picture

Have you cleared your cache?

welly’s picture

Have you cleared your cache?

Many, many times.

Jaypan’s picture

What is the template file name.

welly’s picture

It was named block--webform-contact-us.tpl.php. See a screen capture below from devel_themer:

http://i.imgur.com/MNxpusB.png

The files block--webform-contact-us.tpl.php AND block--webform-client-block-113.tpl.php both exist in my theme, however block--webform-contact-us.tpl.php is ignored whether block--webform-client-block-113.tpl.php exists or not.

The following screen capture from devel_themer shows the candidate template files when I've removed the template file block--webform-client-block-113.tpl.php

http://i.imgur.com/c6rER5n.png

Note, both these files exist in my theme folder. This is just one instances of Drupal not recognising or ignoring template files. It has occurred with the Bean module also and a number of other modules I forget off hand. At first I would have thought the issue is due to an error with the module (webform in this case) but that it does occur in other modules makes me think it's a Drupal bug or perhaps there is a way around this problem?

Cheers,

welly

samwilson’s picture

I also am having a similar issue. Clearing cache doesn't fix it. :(

Should the following enable the sites/all/modules/custom/modulename/page--node--custom-type.tpl.php file to be used for pages of type custom_type?

function modulename_preprocess_page(&$variables) {
  if (!empty($variables['node']) && !empty($variables['node']->type)) {
    $variables['theme_hook_suggestions'][] = 'page__node__' . $variables['node']->type;
  }
}
Jaypan’s picture

Templates need to go in the theme, not a module.

doublejosh’s picture

Not true.