Trouble getting the right paths for addHeaderItem and includes

Permalink
Hi,

With concrete5 I keep having the problem of getting the right paths. For instance, if I want to add a CSS file for use with my form.php file (included by add.php and edit.php), this worked when I only had a block :

public function add() {
   $html = Loader::helper('html');
     $this->addHeaderItem($html->css(BASE_URL . DIR_REL . '/blocks/gallery_of_galleries/form.css'));
}


but it does not work anymore since I made a package with the block. My package name is gallery_of_galleries. form.css is in the same folder as form.php, in : packages/gallery_of_galleries/blocks/gallery_of_galleries. How do I enter the correct path in addHeaderItem ? What is the shortest way to get it ?

Another example : to include into form.php a file named "fieldsets.php" and located in packages/gallery_of_galleries/elements, the only thing that I could find that works was :
include(dirname(__FILE__) . '/../../elements/fieldsets.php');

(__FILE__ is form.php here). But I doubt that this is the best way to do it... I tried a lot of different things, and tried c5's built-in "inc" function without success.

Is there a good summary about this somewhere ? Apart from other forum posts from people having the same kind of problems, I could not find something really useful

Thank you

 
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
If you pass the package name, it will look in the package for the resource.

$this->addHeaderItem($hh->css('your_styles.css', 'your_package_handle'));


The built-in inc function you mentioned, I'm not sure how you tried but this works for me:

<?php $this->inc('elements/your_file.php'); ?>


I don't have to pass the handle for inc though.
Onox replied on at Permalink Reply
Thanks for your input ! However, I really cannot get it to work like you do. addHeaderItem seems to only work with the full path from the root for me, something like :
$this->addHeaderItem($html->css(BASE_URL . DIR_REL . '/'. DIRNAME_PACKAGES . '/gallery_of_galleries/blocks/gallery_of_galleries/form.css'));


I think I am going to do it like this from now on, unless I come across a better solution
goodnightfirefly replied on at Permalink Best Answer Reply
goodnightfirefly
REL_DIR_PACKAGES can replace your BASE_URL . DIR_REL . '/' . DIRNAME_PACKAGES combo.

<?php echo REL_DIR_PACKAGES . '/your_package/'; ?>


EDIT: Also I should point out that a 'view.css' file automatically gets loaded if present in your block folder.
Onox replied on at Permalink Reply
Thank you :) I'll read the code to better understand how inc works (I find myself doing this a lot anyway, since many things are missing or outdated in the documentation =( ). I used it successfully in my add.php and edit.php to include form.php in the same folder, but not anywhere else.