Module template /modules/mod_my_module/tmpl/default.php
:
$wa = $app->getDocument()->getWebAssetManager();
$wr = $wa->getRegistry();
// Registering `media/mod_my_module/joomla.asset.json` file.
$wr->addExtensionRegistryFile('mod_my_module');
if ($wa->assetExists('style', 'mod_my_module.custom-style')) {
// Module assets manifest is registered but not parsed. So, all module assets are considered as not existing.
$wa->useStyle('mod_my_module.custom-style'); // This line will never be executed.
} else {
// The default stylesheet is always used.
$wa->useStyle('mod_my_module.default-style');
}
Module assets manifest /media/mod_my_module/joomla.asset.json
:
{
"$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
"name": "mod_my_module",
"version": "1.0.0",
"description": "My Module",
"assets": [
{
"name": "mod_my_module.default-style",
"type": "style",
"uri": "mod_my_module/default.css"
},
{
"name": "mod_my_module.custom-style",
"type": "style",
"uri": "mod_my_module/custom.css"
}
]
}
Both files /media/mod_my_module/css/custom.css
and /media/mod_my_module/css/default.css
exist. Only
/media/mod_my_module/css/custom.css
should be included into the document, because it is defined (exists) in the /media/mod_my_module/joomla.asset.json
file.
At a check-up, the module asset manifest is registered but not parsed. So, all module assets are considered as not existing. The stylesheet /media/mod_my_module/css/default.css
is included into the document instead of /media/mod_my_module/css/custom.css
.
Joomla! 4.3.3 Stable [ Bora ] 11-July-2023 16:00 GMT
Neither the Joomla\CMS\WebAsset\WebAssetRegistry::addRegistryFile
nor the Joomla\CMS\WebAsset\WebAssetManager::assetExists
functions parse the class variable Joomla\CMS\WebAsset\WebAssetRegistry::$dataFilesNew
which holds newly added assets registries. The function Joomla\CMS\WebAsset\WebAssetRegistry::parseRegistryFile
is protected
, so can not be called from the template of the module.
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
bug
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-08-22 13:21:48 |
Closed_By | ⇒ | Fedik |
Yeap,
Parsing done on
WebAssetRegistry::get
and missing onWebAssetRegistry::exists