addHeaderItem with add/edit mode of a block

Permalink
I've stumbled over a problem I wasn't able to solve yet.

On my block the add.php and edit.php are exactly the same and both simply include form.php. When I use addHeaderItem on form.php to inject some css into the header, it works when block is on editing mode, but not when adding a new block.

What I want to do is using the css code (together with some jquery) on the block config page itself, not for the block output on the website.

When I go to block's edit mode and look at html source, I can identify the the injected code correctly, but when I add the same block it is missing on HTML source. For editing mode all works perfect, for addind not. Why ?

I tried using addHeaderItem from my form.php, but also from add.php and edit.php, from the controller etc.. with no success. Any idea ?

sascha
 
defunct replied on at Permalink Reply
defunct
sascha replied on at Permalink Reply
sascha
Thanks, but unfortunately that doesn't work for me, too.

I tried this earlier, but gave it a second chance now (in case I should have made a mistake somewhere). With the same results - no injection support within the "Add" frame/window, but no problem within the "Edit" frame/window of a block. I guess the block must be installed on a page before the injection of code works. If it has been installed once, there are no problems with "Add" window for further blocks of the same type.

For me the solution was adding the css code to the HTML page using style tags, instead of an external css file. Works nice.

Nevertheless thanks for your help !
glockops replied on at Permalink Reply
glockops
The controller methods you would want to use are edit() and add(), not on_page_view().

If you want to use addHeaderItem() to add css or javascript to the head when editing or adding a block you can do it through the block's controller such as:
public function edit() {
  $this->includeFiles()
}
public function add() {
  $this->includeFiles()
}
private function includeFiles() {
  $html = Loader::helper('html');
  $this->addHeaderItem($html->css('block.css','package_handle');
}


block.css should be located in the package's CSS folder (/packages/yourpackage/css/block.css) - Javascript in a JS folder. Add as many css and js files as needed. Don't forget you can include Javascript by using a file called auto.js which is automatically included on block add/edit.

For the front-end (visitor's view) javascript and css files can be included by putting the files in the block's css/ and js/ folders or by naming the files view.css and view.js and including them in the block's root folder.

References:
http://www.concrete5.org/documentation/developers/blocks/mvc-approa...
http://defunctlife.com/2009/08/injecting-header-items-into-a-block/...
http://c5cookbook.com/docs/blocks...

*Edit 12:38PM 2011-11-1 for clarity.
JohntheFish replied on at Permalink Reply
JohntheFish
Whilst what you are doing is not ajax, the howto & block ajax lessons covers a similar issue to the add/edit issue you are having and may offer some help.