Injecting header items into a block

CMS, Web Development

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.

2 Comments

  1. mohdizuddin says:

    Great sharing. I’m subscribing to your site now. Thanks :)

  2. Tim Gurske says:

    Saved me alot of frustration! Thanks!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>