08/23/09
Injecting header items into a block
Many times you need to inject includes of javascript or css into the header instead of writing the include path into add.php or edit.php. This is a much cleaner solution and can be accomplished in the blocks controller.php. In this example I include both swfobject and jquery’s colorpicker libraries as well as the jquery colorpicker Concrete5 css file:
/*
* include swfobject and colorpicker in the header
*/
public function on_page_view() {
$html = Loader::helper('html');
$this->addHeaderItem($html->javascript('swfobject.js'));
$this->addHeaderItem($html->javascript('jquery.colorpicker.js'));
$this->addHeaderItem($html->css('ccm.colorpicker.css'));
}
Using the on_page_view() function easily accomplishes this.
Great sharing. I’m subscribing to your site now. Thanks
Saved me alot of frustration! Thanks!