addHeaderItem from block

Permalink
I have an element to load lightview:
<?php defined('C5_EXECUTE') or die("Access Denied.");
$html = Loader::helper('html');
$v = View::getInstance();
$lightview = '<!--[if lt IE 9]>';
$lightview .= $html->javascript('excanvas/excanvas.js');
$lightview .= '<![endif]-->';
$lightview .= $html->javascript('spinners/spinners.js');
$lightview .= $html->javascript('lightview/lightview.js');
$lightview .= $html->css('lightview/lightview.css');
$v->addHeaderItem($lightview);


I call it with Loader::Element('lightview');
When using this on a single page it works as expected, but when using it from a block that needs it nothing happens.
Why? Am i doing something wrong? Is it not possible to add header items from a block?

 
Mnkras replied on at Permalink Reply
Mnkras
There are several ways to add items I the header. On way is to make a j and CSS directory in the block's folder. The other way is to add the header code in the on_page_view method of the block controller. Also, as a suggestion, don't add them all in me block like that, split it up.

Mike
rklomp replied on at Permalink Reply
Thanks. The on_page_view function did it.

What do you mean with:
don't add them all in me block like that, split it up.