Dynamic Block .tpl auto suggestion

Public

Adds a custom auto suggestion tpl file ito all blocks with machine name containing the input string. Allows you set a different block theme template .tpl.php file based on the machine name of block.

Get raw version
php
  1. // set up string to search for within machine name and tpl file to use for all blocks that contain this string
  2.  
  3. $machinepart = 'examplename';
  4. $mytpl = 'myblocktheme.tpl.php';
  5.  
  6. // implement hook _preprocess_block to set tpl file based on block id
  7. function mytheme_preprocess_block(&$variables, $machinepart, $mytpl) {
  8.  
  9. $machine = $variables['attributes_array']['id'];
  10.  
  11. if (strpos($machine, $machinepart)) {
  12. $variables['theme_hook_suggestions'][] = $mytpl;
  13. }
  14.  
  15. }