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:
'asset_groups' => array(
  'tooltipsmall' => array(
    array(
      array('javascript', 'js/jquery-ui.min.js', array('position' => 'F', 'minify' => false, 'combine' => false)),
      array('css', 'js/jquery-ui.min.css', array('position' => 'F', 'minify' => false, 'combine' => false))
    )
  )
)


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?

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi Kiesel,

Here are two examples of loading the jquery/ui asset group.

in view.php
View::getInstance()->requireAsset('jquery/ui');

in your block controller view() method
$this->requireAsset('jquery/ui');
Kiesel replied on at Permalink Reply
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.
A3020 replied on at Permalink Reply
A3020
Your array should be defined as an asset, not as an assetgroup.

If you check app.php again, you'll see the difference.
Kiesel replied on at Permalink Reply
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.
andrew replied on at Permalink Reply
andrew
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:

$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'),


then you can just call

$this->requireAsset('highlight-js');


from within a controller.