Trying to use registered asset in package for core block with templates

I am pulling my hair out here trying to make sense of how on earth I’m supposed to use assets I register in my somehow esoteric scenario (which shouldn’t be an esoteric scenario).

I have my package where I have multiple templates for core blocks (express_entry_list & express_entry_detail).

I am trying to register wow.js & animate.css in such a way that I can invoke them when either of these blocks are used.

From what I can tell, I have to use a controller.php at the package/blocks/express_entry_list/controller.php level (replacing express_entry_list with express_entry_detail for that block), and not within each template. Okay fine, except I cannot for the life of me get this damned controller.php to actually EXECUTE.

In my test environment all caching is off (Dashboard settings).

I have tried registering the assets in either packageroot/controller.php (in the on_start() function), and/or in the package/blocks/express_entry_list/controller.php file (in the on_start() function, and/or the registerViewAssets() function), and I cannot tell if the registration happens, but when I try to also require the asset(s) the diagnostic (F12) console doesn’t show ANY of the files being loaded (using $this->requireAsset(‘whatever’); in either the controller.php for the block, as described above in either on_start() or the regisaterViewAssets() function)

I CANNOT for the life of me figure out why my controller.php for a core block is not loading (so far as I can tell). I do not want to change the core functionality of these blocks, I just want to template them, and load js + css assets in the “asset registration” method, which is supposed to be the way to go, to reduce duplication, etc, but my scenario is somehow insufficiently documented and not enough examples exist.

Before I start posting any example code, I want to understand what the method I SHOULD be using in this scenario is? Every single controller.php override example I see talks about putting them in application/blocks/blockname/controller.php and not about usage in packages, in this scenario. Also, because I’ve gone through so many iterations, I can’t exactly accurately (while being not-overly-verbose) represent what code I have tried.

So… this should as hell be easier than it seems to be. And I have even gone so far as to verify that the filesystem permissions are correctly set for both controller.php files!

ARGH I’m losing hair here! Can I please get help? I seriously feel like I’m doing something basic and wrong, but I cannot find what after exhaustive research.

Are these assets part of the core? If not the just add a view.css and view.js file to each template folder

No they are not part of the core, otherwise the assets would already be registered. I’m trying to register wow.js and animate.css so I can use them across the whole package, not just on single templates.

The justification for the asset registration method, over the method you’ve proposed, is that the asset registration method is touted as a way to avoid duplication of js/css/assets. In that, if I were to stuff the js/css into view.js / view.css and I want to use the js and css for multiple different blocks/templates, then that js/css would exist in the client browser multiple times over, and the asset registration system is meant to prevent this duplication of code.

I have, as a temporary work-around, used view.js and view.css, but that really does not look like the best long-term solution, and asset registration looks to be the way to go (hence me spending so much time trying to learn it).

My mistake I understand what your trying to do now.

Try adding code like this to the controller.php in you package root.

public function on_start() {

	$al = AssetList::getInstance();
//Register wow.js
	$al->register('javascript', 'wow', 'js/wow.js', array('version' => '1.0.0', 'position' => Asset::ASSET_POSITION_HEADER, 'minify' => false, 'combine' => false), $this);

Then in your theme add this to you page_theme.php file

public function registerAssets() {
$this->requireAsset(‘javascript’, ‘wow’);

I don’t have a page theme, and I am not going to make a page theme. These are block templates.

As I understand it. The only way to register assets to use a cross the whole site is within you site theme, as I have described.

Other wise if you want CSS and js to pull in on you block templates using the veiw.css and view.js option is there.

I will keep on eye on this thread if someone else knows or I have forgotten something.

  1. My package doesn’t include a site-wide theme at all, it’s really just for block templates.
  2. I tried using a controller.php for the block itself in the package and using that to register and require the css/js content, but that didn’t seem to actually get executed, for reasons I don’t know/understand.
  3. The whole asset registration system is supposed to be to avoid duplication of code import via view.css and view.js as I have multiple blocks and multiple block templates on the same page that I want to use the js/css for (not using page templating in this package, again).

So… yeah for now I’m using the view.css and view.js method, but so much of what I read from the documentation/elsewhere convinces me this is the “wrong”/not-ideal way to do it.

I appreciate your thoughts on this, but I’m still in the pickle, thanks anyways! :slight_smile:

Also, to clarify, if I can’t “register on the whole site” then at least have them register when I use a template for a block (or when I use that block, eg express_entry_list). So that when that template/block (preferably template) are called, the js/css payload is registered.

If you know of a way relevant for this clarification, please let me know! My many attempts have not gotten me anywhere workable :frowning:

It sounds like you have the assets registered in your Package controller.php and you are trying to use them in a Block controller.php, is that right?

If so, where are you putting the Block controller.php and what do you have in it? The only way I have been able to make this work is to put the Block controller.php in the Application directory and conditionally call it in the registerViewAssets function, like this

public function registerViewAssets($outputContent = '')
    if (is_object($this->block) && $this->block->getBlockFilename() == 'responsive_header_navigation') {
        $this->requireAsset('javascript', 'jquery');
1 Like

I tried having the block controller.php in packageroot/.blocks/express_entry_list/controller.php

The latest attempt is…


namespace Concrete\Package\PackageName\Block\ExpressEntryList;

use Concrete\Block\ExpressEntryList\Controller as BlockController;

class Controller extends BlockController
    public function on_start()

Take note that wow is defined as a registered Group. I have also tried the same with the individual assets being registered (instead of trying to require-invoke the group). To no avail so far.

I do not believe you can override a block controller in a package.

Does your controller get called at all?

I have really seen no evidence that the controller.php for the block gets called :frowning: But the documentation sure seems to say (so far as I can tell) that it SHOULD when I put it in that location (I think this is one of the relevant sections : Using a Custom Controller for a Core Block Type )

@BloodyIron I don’t believe you can override like that either. It surely would be nice to load assets on a template basis, and I believe that’s what you’re basically asking here. Here’s a git thread I’ve been following in regards: Assets/Features per block template · Issue #11067 · concretecms/concretecms · GitHub

Curses! Also, thanks for linking to that issue :slight_smile: I’ve thrown my hat in the ring!