Magento Forum

   
Only load stylesheet on Widget pages
 
bhamrick
Jr. Member
 
Total Posts:  3
Joined:  2011-02-08
 

How can I dynamically load stylesheets into the “head” section in Magento only on pages that include a custom Widget?

For my scripts I’m doing this:

if($this->getLayout()->getBlock('namespace_module_scripts')==false{
    $block 
$this->getLayout()
        ->
createBlock('core/template''namespace_module_scripts')
        ->
setTemplate('namespace/module/scripts.phtml');
    
$this->getLayout()->getBlock('before_body_end')->insert($block);
}
This is the current content of _prepareLayout() in my Widget block class. I tried using the same method for styles, swapping before_body_end for head, and that worked great for placing Widget Instances or manually placing the block in my layout xml, however when inserting a widget inline in a Page’s content the head section seems to be rendered prior to the Widget, and therefore my styles template can’t be inserted into the head block.

My (hopefully) temporary solution is to load the styles on every page in my layout xml. Is there a better way to do this?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top