Created
March 1, 2012 00:13
-
-
Save rosemarydotworld/1945947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//give blocks semantic html ids and theme hook suggestions | |
function wmux_preprocess_block(&$vars) { | |
$semantic_block_id = wmux_id_safe($vars['block']->subject); | |
$vars['semantic_block_id'] = $semantic_block_id; | |
$vars['theme_hook_suggestions'][] = 'block__' . $semantic_block_id; | |
} | |
function wmux_id_safe($string) { | |
if (is_numeric($string)) { | |
$string = 'n'. $string; | |
} | |
return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string)); | |
} |
On the advice of David Gibb, tried the following without success:
$vars['theme_hook_suggestion'] = 'block__' . $semantic_block_id;
Solved by Sam Richard. Here's what I should have been doing on line 14:
return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '_', $string));
Notice the underscore in the place of the dash.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea is that all blocks become themeable with a template file based on their title:
Using devel_themer, I can confirm that the theme_hook_suggestions array shows my new value. However, blocks don't actually take the new template when their titles mean they ought to. Is it possible that I'm adding to the theme_hook_suggestions array after the block already decides upon a template?