Javascript in Packages

Permalink
Javascript in a packaged blocks js direcory is not loading automatically. Do we have a different way now to load javascript?

pvernaglia
 
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
I just found this out, too. I've been playing around with getting my addons to work with 5.7, and here is what I found.

It seems that you pretty much have to load the script via the Footer. Below is the updated code to add to the controller:

public function view() {   
         $b = $this->getBlockObject();         
         $btID = $b->getBlockTypeID();
         $bt = BlockType::getByID($btID);
         $uh = Loader::helper('concrete/urls');
         $this->addFooterItem('<script type="text/javascript" src="' . $uh->getBlockTypeAssetsURL($bt) . '/js/someScript.js"></script>');
      }

This seems to work, as far as loading the script. However, maybe there's a better way that I don't know of yet. I believe they are still working on the documentation for 5.7 yet.
mnakalay replied on at Permalink Reply
mnakalay
@pvernaglia
That's weird I actually had a different problem, the javascript was loading but css files in the packaged block's CSS folder were not loading. I submitted a bug report and Andrew said it was fixed in next version (7.0.2)

view.js and view.css are both loading correctly though.
pvernaglia replied on at Permalink Reply
pvernaglia
After working on this some more, I think you are right, it was the missing CSS that was messing up