addHeaderItem incorrect path

Permalink
Hi,

I am building a custom block and would like to include additional CSS in my add.php and edit.php.

I've read that the recommended way to do so is the following :

in controller.php :

public function edit() {
   // ...
   $html = Loader::helper('html');
   $this->addHeaderItem($html->css('./blocks/gallery_to_fancyboxes/form.css'));
}


However, I cannot get the right path to be included. The problem is that when I check the source code of my index.php concrete5 web page, I see that concrete5 automatically transformed this path into :

/concrete5/concrete/css/./blocks/gallery_to_fancyboxes/form.css?ts=1406028710935

Which of course is not what I want, since my form.css file is located in ./blocks/gallery_to_fancyboxes/form.css relative to index.php. I have checked that the CSS file is indeed taken into account if I manually change the path to ''./blocks/gallery_to_fancyboxes/form.css" using Firefox's inspector.

I also tried to write the path parameter differently in the addHeaderItem function, for example without the "./" at the beginning, but nothing works !

Please could you tell me how I should do it ? Many thanks

 
exchangecore replied on at Permalink Reply
exchangecore
Hmmm maybe try removing the . from your path?

$this->addHeaderItem($html->css('/blocks/gallery_to_fancyboxes/form.css'));
Onox replied on at Permalink Reply
Thank you for your answer, but no, I had already tried this. If I write it like you did, the href attribute of the link tag is : href="/blocks/gallery_to_fancyboxes/form.css, and it does not work, because, if I am not mistaken, the leading slash means that it is an absolute path from the root, and this is not the case here.
exchangecore replied on at Permalink Best Answer Reply
exchangecore
You could try manually adding the relative directory constant perhaps?

$this->addHeaderItem($html->css('/' . DIR_REL . '/blocks/gallery_to_fancyboxes/form.css'));


If that doesn't work you could try doing

$this->addHeaderItem($html->css(BASE_URL . DIR_REL . '/blocks/gallery_to_fancyboxes/form.css'));
Onox replied on at Permalink Reply
Your second line works, thank you ! Although I wonder if this is really the way it should be done, as it seems a little complicated :p

And out of curiosity, why does it add a parameter called ts at the end of the url (?ts=1406033219585) ?
exchangecore replied on at Permalink Reply
exchangecore
If I were making an educated guess, the ts= probably has something to do with file caching. That way when you change your css file it gets a new ts= number or if you have caching disabled it might get a new one every page load to prevent browser caching of the file on the client side. That's just a guess though.

Don't forget to mark the correct answer. - Thanks