// access from administrator component
$app = CMSApplication::getInstance('site'); // Joomla\CMS\Application\SiteApplication
$template = $app->getTemplate(true); // throws exception
return site template
throws exception
J3.9.18
finds the template, but throws exception when verifying the template really exists.
"file_exist" in SiteApplication.php (line 544/561) should check against JPATH_SITE.'/templates' instead of JPATH_THEMES.
work around: create (empty) index.php in folder /administrator/templates/my-site-template-name/
Well, the active template. The code finds everything correctly, just replace JPATH_THEMES as I suggested.
Well, the active template.
If you have several templates and/or styles: What is the active template when you are in the back-end?
It depends on the active page (menu item) in the front-end which template or style is active.
That's what I don't understand.
Maybe I should add that the 2 lines of code I posted finds the active site template without any issues, when called from the front-end, since JPATH_THEMES points to /templates. But when called from the back-end, JPATH_THEMES points to /administrator/templates. As it's an instance of SiteApplication, everythings works for the back-end as well (it finds the template in the db), up to the point when the code checks whether the template found does exist on the file system. It's there were it should check against /templates/, but it does check against JPATH_THEMES which points to /administrator/templates/.
Well, the active template. The code finds everything correctly, just replace JPATH_THEMES as I suggested.
Provide a pr if you think so: https://docs.joomla.org/Using_the_Github_UI_to_Make_Pull_Requests
Maybe I should add that the 2 lines of code I posted finds the active site template without any issues,
But not the active style which is the important thing? A template can have many styles and the params are for the style not for the template
Maybe I should add that the 2 lines of code I posted finds the active site template without any issues, when called from the front-end,
I think you mean the template marked as "Standard". But these params can be completely irrelevant. There are cases where the Standard template is never used in the front-end.
True, but in my case I just use one template in the front-end. If I read the code correctly then getTemplate tries to identify the menu item and the template active for that menu item. If it can't figure it out, then the template active for the home item is selected and returned. Called from front-end ok, called from back-end throw exception with conclusion that the template does not exist in the file system. Certainly not what I would expect.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-12 10:36:44 |
Closed_By | ⇒ | joomdonation | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
The problem here is that we use JPATH_THEMES to check for existence of the template. Unfortunately, JPATH_THEMES is coupled with the active application, mean administrator app in this case, result in the template does not exist error
We also could not changed the code to JPATH_SITE.'/templates' as you suggested because Joomla allows custom defined constants.
So while the issue is valid, I'm afraid of it will be a won't fix issue for the time being. Please use the workaround you found or any working custom code (I also write custom code myself to detect the template).
How should the backend know which params of several possible site templates/styles you want?