addHeaderItem not adding header item

Permalink
In a block, I have:

public function view() {
    $categories = Category::all();
    $this->set("categories", $categories);
    $html = Loader::helper('html');
    $this->addHeaderItem($html->css('my.css', 'my_block'));
  }


I've cleared the cache in Concrete, killed the browser cache, and I can't seem to get the css file to be added to the page. Any ideas?

blakeage
 
blakeage replied on at Permalink Reply
blakeage
Very weird. I moved the css addHeader stuff to the on_page_view() method in the controller and now it loads. It's weird because I have another block that I created a while back (same site, it was just installed before I upgraded to 5.6.1.2) that had virtually the same code (the css was loaded in the view() method) and it works fine. ???
mnakalay replied on at Permalink Reply
mnakalay
is your block in a stack or something?
blakeage replied on at Permalink Reply
blakeage
No, it's just in the main page area.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Well according to C5 core team about on_page_view:

[quote]This function is automatically run when the block is viewed from within a page. That makes it useful when with $controller->addHeaderItem(). This is the only way to inject items into the page's header from within a block.[/quote]

So IN THEORY, view() should not do the trick

If you want to know more go there:
http://www.concrete5.org/documentation/developers/blocks/mvc-approa...
ssdscott replied on at Permalink Reply
ssdscott