addHeaderItem from within block

Permalink
Stumped again, I should change my username to that.

Anyways, instead of adding arbitrary javascript throughout my pages, I want to use the controller method addHeaderItem from within a block.

I have tried a few different things, but I am posting here so that means they haven't worked :)

I tried $controller->addHeaderItem(array or string) and $this->$controller-> same thing.

All I am doing is adding header items to the blockcontroller as I can see in my debugger. I know this is a scope issue and probably simple syntax but I am at a loss of what to do and I don't want to sit down with a drink at 1:30, or do i? :)

ScottC
 
Remo replied on at Permalink Reply
Remo
yes that would be great..

I suggested somewhere else that we could create a file like auto.js that gets included in the header if it's there..

addHeaderItem would be nicer though..
ScottC replied on at Permalink Reply
ScottC
Method exists and is used to populate the header in concrete/elements/header_required.php

I guess I just don't have a grasp on the flow of the page rendering and where I would be able to use the method that is available in anything that extends controller.
Remo replied on at Permalink Reply
Remo
I think this is not working, not because you don't understand the flow of the application but simply because it's not called again at that time..

From what I've seen outputHeaderItems has been called before you're block constructor has been executed.

public function __construct() {
   parent::__construct();
   $this->addHeaderItem('<script type="text/javascript">alert(123)</script>');   
   $this->outputHeaderItems();
      }


it's a bit silly but it's shows how it works. The code above is part of a block. It adds a script to headerItems but this gets never printed unless you call outputHeaderItems again (which is stupid). It prints the javascript right into the body where it shouldn't be...

But please correct me if I'm wrong (Andrew :-)
ScottC replied on at Permalink Reply
ScottC
I thought that this was the case :). I will wait for Andrew to weigh in on this one as well.
Remo replied on at Permalink Reply
Remo
I hope I'm wrong!
ScottC replied on at Permalink Reply
ScottC
I was over thinking it. I searched the entire project looking for head *har* header etc. This file only takes a few arguements, if the page is or isn't in edit mode or arrange mode, it isn't looking for block input.

The function exists solely to be used in header_required.php which basically prints out the stuff for the head of the page and if it is in edit mode it includes page_controls which prints out more stuff with the other printed stuff.

With the release I am working with 5.1 it would require a fork to enable this functionality using this method, i am sure c5 will sprout a new one :).
andrew replied on at Permalink Reply
andrew
Remo's already touched on this but unfortunately he is right: add header items won't work from within a block's controller. This is really too bad, and something we want to change: obviously, it would be very cool if you could load up block-specific style sheets, but then they'd all be output at the same time, at the same place, in the proper area of the page (the <HEAD> portion) rather than haphazardly through the page.

As you can imagine, since blocks are rendered in the page as they're encountered, this is a big challenge, and it's requiring some reorganization to how we render blocks, but it's something that we'd like to do.

As other's have said, this should work in the page's controller.
shadowcomputers replied on at Permalink Reply
shadowcomputers
Hi,

Has there been any progress on how to do this yet?

Many thanks, Steve
powermick replied on at Permalink Reply
powermick
Following the discussion by:
http://www.concrete5.org/index.php?cID=4437...