3

I'm a little confused on the documentation for adding assets to my component, and getting an error message:

There is no "com_supersite.supersite" asset of a "script" type in the registry.

I have a media reference in my manifest file:

<media destination="com_supersite" folder="media">
    <file>joomla.assets.json</file>
    <folder>css</folder>
    <folder>js</folder>
</media>

My joomla.assets.json file, which I think should register my assets:

{
  "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
  "name": "com_supersite",
  "version": "4.0.0",
  "description": "Joomla CMS",
  "license": "GPL-3.0-or-later",
  "assets": [
    {
      "name": "com_supersite.supersite",
      "type": "script",
      "uri": "com_supersite/supersite.js",
      "dependencies": [
        "core"
      ],
      "attributes": {
        "defer": true
      }
    },
    {
      "name": "com_supersite.supersite",
      "type": "style",
      "uri": "com_supersite/supersite.css"
    }
  ]
}

And then trying to use the script asset in my component view:

<?php

use Joomla\CMS\Factory;

\defined('_JEXEC') or die('Restricted access');


/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

$wa->useScript('com_supersite.supersite');

2 Answers 2

3

Per documentation, the web asset registry file must be named joomla.asset.json, not joomla.assets.json to be loaded automatically.

1
  • Thanks @Sharky, my answer worked but it's good to keep with the standards.
    – James
    Dec 13, 2022 at 22:20
2

@Sharky, you were right to call my original answer incorrect. I wasn't paying enough attention to the names in the asset file compared to the error message received.
I updated the joomla.asset.xml file, and now I don't need to register the scripts.

{
  "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
  "name": "com_supersite",
  "version": "4.0.0",
  "description": "Joomla CMS",
  "license": "GPL-3.0-or-later",
  "assets": [
    {
      "name": "supersite",
      "type": "script",
      "uri": "com_supersite/supersite.js",
      "dependencies": [
        "core",
        "jquery"
      ],
      "attributes": {
        "defer": true
      }
    },
    {
      "name": "supersite",
      "type": "style",
      "uri": "com_supersite/supersite.css"
    }
  ]
}

Component View:

<?php

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;

\defined('_JEXEC') or die('Restricted access');


/** @var CMSApplication $app */
$app = Factory::getApplication();

$wa = $app->getDocument()->getWebAssetManager();

$wa->useStyle('supersite')
    ->useScript('supersite');
2
  • This answer is factually incorrect. If you use a registry file , you don't need to manually register assets in the component.
    – Sharky
    Dec 14, 2022 at 6:26
  • @Sharky answer updated, thanks for your help.
    – James
    Dec 24, 2022 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.