I was attempting to rationalize the CSS for my site, which was getting a bit unwieldy.
Following the example of the views theme wizard, I thought it would be clever to place my block-specific css into its own little file.
In the top of my block.tpl.php I placed
if(file_exists( $css = path_to_theme() .'/block-'. $block->module .'.css')){
drupal_add_css($css);
}
So that
- When this block gets invoked
- If it has a custom css available
- That CSS is added to the list.
Sounds tidy? Pretty much the way that phptemplate does its thing?
No.
This worked perfectly when the block was in the left or the right but not when it was in a custom region for my theme.
Due to the order of operations in phptemplate.engine:phptemplate_page()
- left sidebar is pre-themed
- right sidebar is pre-themed
- Other standard page variables are pre-themed, including the '$styles' list
- Remaining custom variables (and the blocks that are to go in my custom region) are themed
-- page is rendered via page.tpl.php (which renders the $styles css tags)
The effect is that the $styles are compiled prematurely, and the drupal_add_css() I called in my custom region block never works!
:(
Arg.