Include .js in dashboard single page

Permalink
Hello,

I'm writing a package for C5.7 and in a particular dashboard single page I'm gonna build an Angular app. I could use the following code in my_angular_single_page.php:

<?php echo URL::to('/packages/my_package/js/angular.min.js') ?>


But is there a better and more proper way to do this?

View Replies:
ramonleenders replied on at Permalink Reply
ramonleenders
Yup there is. Register assets in the on_start function and require the asset in your (view) function! See the code below

public function on_start()
    {
        $al = \Concrete\Core\Asset\AssetList::getInstance();
        $al->register('javascript', 'some-identifier-name', 'js/angular.min.js', array(), 'your_package_handle');
    }
    public function view()
    {
        $this->requireAsset('javascript', 'some-identifier-name');
        // other view function code here
    }
hawkagent replied on at Permalink Reply
Thanks, this seems to include the javascript files, unfortunately this seems to break my angular app because the libraries are included at the end of the page. Is it possible to tell concrete to include the javascript files in the header of the page?
MrKDilkington replied on at Permalink Reply
MrKDilkington
@hawkagent

The register() method takes an $args array for setting asset position.

register( string $assetType, string $assetHandle, string $filename, array $args = array(), boolean $pkg = false )
http://www.concrete5.org/api/source-class-Concrete.Core.Asset.Asset...

Try this
$al->register('javascript', 'some-identifier-name', 'js/angular.min.js', 
array('version' => '1.0', 'position' => Asset::ASSET_POSITION_HEADER, 'minify' => true, 'combine' => false), 'your_package_handle');