Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By welly on
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
Have you cleared your cache?
Have you cleared your cache?
Have you cleared your cache?
Many, many times.
What is the template file
What is the template file name.
It was named block--webform
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
I also am having a similar
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 typecustom_type
?Templates need to go in the
Templates need to go in the theme, not a module.
Not true
Not true.