Add JavaScript or CSS in Block class

 To add JavaScript or CSS files to the head section of the resulting HTML page, you can add something like this to the _prepareLayout function of a Block class:

$headBlock  = $this->getLayout()->getBlock('head');
As you can see, we can use the layout model to get the head block an use its functions to add files.
This doesn’t work inside of the default constructor of the Block class.
For further information, have a look to class Mage_Page_Block_Html_Head.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.