How to use requireAsset in Package Custom template for core blocks?

Permalink
Hello guys,

I am having issues with the requireAsset('xyz') method for custom templates I have developed in a package for core blocks.

A case in point, I have made a custom template for the image slider but I am unable to use requireAsset inside my package block controller.php override for the imageslider.

I am therefore forced to use View::getInstance()->requireAsset('xyz') in view.php but it doesn't work reliably as sometimes the assets are not included in the page.

Here is my block controller override in htdocs\c5site\packages\c5dev\blocks\image_slider\controller.php

<?php
namespace Concrete\Package\c5dev\Block\ImageSlider;
use Concrete\Block\ImageSlider\Controller as ImageSliderBlockController; // InheritedBlockController
class Controller extends ImageSliderBlockController {
   public function registerViewAssets() {
      $this->requireAsset('myassetgroup-registed-in-package-onstart');
   }
}


Note: overrides cache turned off

What am I missing?

 
razorcommerce replied on at Permalink Reply
razorcommerce
I'm not sure of the answer but it's an interesting problem... code looks correct, except I don't know what your asset group registration looks like. I support the package on_start does run before the block controller? Have you tried registering an individual file there instead of a group, just to see if that changes anything?
martbase replied on at Permalink Reply
Here is my package onstart - actual assets replaced with assettest and extratest

Top level package js and css directories used for shared assets
htdocs\c5site\packages\c5dev\css\assettest\jquery.assettest.css
htdocs\c5site\packages\c5dev\js\jquery.assettest.min.js

public function on_start()
   {   
      $pkg = $this;
      $al = AssetList::getInstance(); // prefer minimized assets xyz.min.js
      $al->register('css', 'assettest', 'css/assettest/jquery.assettest.css', array('local' => true, 'version' => '4.1.2'), $pkg);      
      $al->register('javascript', 'assettest', 'js/jquery.assettest.min.js', array('local' => true, 'version' => '4.1.2'), $pkg);
      $al->register('javascript', 'extratest', 'js/jquery.extratest.min.js', array('local' => true, 'version' => '1.0.11'), $pkg);
      $this->requireAsset('myassetgroup-registed-in-package-onstart');
      $al->registerGroup('myassetgroup-registed-in-package-onstart', array(
         array('css', 'assettest'),
         array('javascript', 'assettest')
      ));
      $al->registerGroup('extratest', array(
         array('javascript', 'extratest')
      ));