No Code Attached Yet
avatar regularlabs
regularlabs
22 Nov 2021

I have this code:

$asset_manager = JFactory::getApplication()->getDocument()->getAssetManager();
$direction     = JFactory::getApplication()->getDocument()->getDirection();

$asset_manager->getRegistry()->addTemplateRegistryFile('atum', 1);

$asset_manager->usePreset('template.atum.' . ($direction === 'rtl' ? 'rtl' : 'ltr'));

This works fine on the admin side.
But on the frontend, it results in:

<link href="/templates/cassiopeia/css/template.css?ac...e2" rel="stylesheet" 
   data-asset-name="template.atum.ltr" data-asset-dependencies="fontawesome" />

So that seems to not be as it should.
Weird thing is that the path of the file is wrong, but the asset-name is right ??‍♂️

Am I doing something wrong? Or does Joomla have a bug here?

avatar regularlabs regularlabs - open - 22 Nov 2021
avatar joomla-cms-bot joomla-cms-bot - change - 22 Nov 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 22 Nov 2021
avatar regularlabs regularlabs - change - 22 Nov 2021
The description was changed
avatar regularlabs regularlabs - edited - 22 Nov 2021
avatar Scrabble96
Scrabble96 - comment - 22 Nov 2021

I can confirm this result and as I am not using the Cassiopeia template, this is causing modal layout problems.

avatar Fedik
Fedik - comment - 22 Nov 2021

yeah well, why it should work? It is asset for the backend template :)

What you got is an expected result.
The Atum css file is template.css

and when you search for it in "front end" context, it will look for this file in an active template first and so it pick /templates/cassiopeia/css/template.css

avatar regularlabs
regularlabs - comment - 22 Nov 2021

If it is expected result, then why does is there a second attribute for the addTemplateRegistryFile method to define the client?
1 = admin, 0 = frontend.

$asset_manager->getRegistry()->addTemplateRegistryFile('atum', 1);

If the Joomla asset manager is not capable of loading admin side files on the frontend (which would be really weird if that is true), then the client attribute in the addTemplateRegistryFile is useless too.

avatar Fedik
Fedik - comment - 22 Nov 2021

then why does is there a second attribute for the addTemplateRegistryFile method

To tell which template registry joomla.asset.json to load:
form /templates/blabla/ or from /administrator/templates/blabla/.

A regular extensions does not have it because it is expected that all their assets is under /media/ folder.

avatar Fedik
Fedik - comment - 22 Nov 2021

If you replace this

to

"uri": "administrator/templates/atum/js/template.min.css",

then it will load what you want.

But there still not reason to do it. All shared assets should be under /media folder.

avatar regularlabs
regularlabs - comment - 22 Nov 2021

Your last comment makes no sense. This concerns the Joomla core admin template. So hacking the joomla.asset.json
file is not a solution. And telling me that the assets should be under /media folder... again... this is core files.

So in other words, there is no clean Joomla core way to load a Joomla core media file from the admin template on the frontend.

avatar HLeithner
HLeithner - comment - 22 Nov 2021

If I'm not completely wrong this PRs should solve this #35874 and #35998

It moves all assets from the templates directory to the media folder

avatar Fedik
Fedik - comment - 22 Nov 2021

Loading assets from admin template on front end (and vice versa) does not make sense.

avatar regularlabs regularlabs - close - 22 Nov 2021
avatar regularlabs
regularlabs - comment - 22 Nov 2021

Editor buttons (modal popups) might want to use assets (styling, etc) that is available in the admin template, and is not in the frontend templates.
But never mind, I stopped caring and have just hardcoded the path to the files to make it load them.

avatar regularlabs regularlabs - change - 22 Nov 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-11-22 15:18:27
Closed_By regularlabs

Add a Comment

Login with GitHub to post a comment