loading AssetGroup
Permalink
These asset groups drive me a little crazy. Everyone says something else and all seems not to work
What I think I found out so far:
I need to declare the asset group in application/config/app.php:
So far so good (I guess?). Now what I need is to call the group. I've read that I can call it globally in application/bootstrap/app.php but that seems not to work at all. So I just load it in the "view" method of the controller.php of one of my blocks.
But it just doesn't work. Declaring and loading single js files works from these files, but with groups it just doesn't. Any ideas?
What I think I found out so far:
I need to declare the asset group in application/config/app.php:
So far so good (I guess?). Now what I need is to call the group. I've read that I can call it globally in application/bootstrap/app.php but that seems not to work at all. So I just load it in the "view" method of the controller.php of one of my blocks.
$this->requireAsset('tooltipsmall');
But it just doesn't work. Declaring and loading single js files works from these files, but with groups it just doesn't. Any ideas?
Hi
Thanks for the answer.That doesn't work though. Maybe with existing core groups or files, but not with the mentioned self-declared group. If I load in the same areas single js or css assets it works, but not a group.
Thanks for the answer.That doesn't work though. Maybe with existing core groups or files, but not with the mentioned self-declared group. If I load in the same areas single js or css assets it works, but not a group.
Your array should be defined as an asset, not as an assetgroup.
If you check app.php again, you'll see the difference.
If you check app.php again, you'll see the difference.
Hi
I know that it works with single assets - that's what I use now. But I figured that asset groups would make more sense. And since they exist... I figured why not use them.
I know that it works with single assets - that's what I use now. But I figured that asset groups would make more sense. And since they exist... I figured why not use them.
Using the array config syntax to define asset groups is a little funky. I think you might be missing some additional things that it needs to fully register. I would try using the PHP API for registering assets and asset groups instead. Here's an example of registering some JS and CSS files and grouping them. Requiring this from a block controller definitely works:
then you can just call
from within a controller.
$al = \Concrete\Core\Asset\AssetList::getInstance(); $al->register( 'css', 'highlight-js', 'assets/highlight/css/concrete5-docs.css', array('minify' => false, 'combine' => false) ); $al->register( 'javascript', 'highlight-js', 'assets/highlight/js/highlight.pack.js', array('minify' => false, 'combine' => false) ); $al->register( 'javascript-inline', 'highlight-js', 'hljs.initHighlightingOnLoad();' ); $al->registerGroup('highlight-js', array( array('javascript', 'highlight-js'), array('javascript-inline', 'highlight-js'),
Viewing 15 lines of 17 lines. View entire code block.
then you can just call
$this->requireAsset('highlight-js');
from within a controller.
Here are two examples of loading the jquery/ui asset group.
in view.php
in your block controller view() method