addInlineScript does not work on 5.1.4
I've developed a module, which inserts an inline script. This works fine on all of my sites but does not on one single site though this has the same joomal version as all the other systems.
There is no error shown it just does not work. Strange is for me that insertion of scripts or styleseets work fine.
I tried to debug but could not find out anything, Checked plugins but its seems that none is involved (e.g. hhtp-header is disabled).
would be great, if someone helps to find out whats going wrong.
$wa->registerAndUseScript("js_weather0", "media/mod_js_weather/js/RGraph.common.lib.js");
$wa->registerAndUseScript("js_weather1", "media/mod_js_weather/js/RGraph.line.js");
$script = $helper->create_inline_script();
$wa->addInlineScript($script);
all scripts should be there
only the script files are ok.
Inline script is missing
joomla 5.1.4
php 8.2.4
Labels |
Added:
No Code Attached Yet
|
hi,
did a print_r on the retuncode of $wa->addInlineScript($script);
saw these first lines;
object(Joomla\CMS\WebAsset\WebAssetManager)#884 (5) {
["registry":protected]=> object(Joomla\CMS\WebAsset\WebAssetRegistry)#518 (4) {
["dataFilesNew":protected]=> array(0) { }
["dataFilesParsed":protected]=> array(6) {
["media\vendor\joomla.asset.json"]=> string(30) "media\vendor\joomla.asset.json"
["media\system\joomla.asset.json"]=> string(30) "media\system\joomla.asset.json"
["media\legacy\joomla.asset.json"]=> string(30) "media\legacy\joomla.asset.json"
["media\plg_system_guidedtours\joomla.asset.json"]=> string(46) "media\plg_system_guidedtours\joomla.asset.json"
["media\plg_behaviour_compat\es5.asset.json"]=> string(41) "media\plg_behaviour_compat\es5.asset.json"
and saw these last infos::
["onWebAssetRegistryChangedAssetOverride"]=> object(Joomla\Event\ListenersPriorityQueue)#591 (1) {
["listeners":"Joomla\Event\ListenersPriorityQueue":private]=> array(1) { [0]=> array(1) { [0]=> object(Closure)#878 (2) {
["this"]=> *RECURSION* ["parameter"]=> array(1) { ["$event"]=> string(10) "" } } } } }
["onWebAssetRegistryChangedAssetRemove"]=> object(Joomla\Event\ListenersPriorityQueue)#880 (1) {
["listeners":"Joomla\Event\ListenersPriorityQueue":private]=> array(1) { [0]=> array(1) { [0]=> object(Closure)#607 (2) {
["this"]=> *RECURSION* ["parameter"]=> array(1) { ["$event"]=> string(10) "" } } } } } } } } ["activeAssets":protected]=> array(1) { ["script"]=> array(3) { ["xx_weather0"]=> int(1) ["xx_weather1"]=> int(1)
["inline.fdd212cdd0684aec80324a770a7a7748"]=> int(1) } } ["locked":protected]=> bool(false)
["dependenciesIsActual":protected]=> bool(false) ["sortedAssets":protected]=> array(1) { ["script"]=> array(0) { } } }
on my working system I get:
RECURSION* [parameter] => Array ( [$event] => ) ) ) ) ) ) ) ) [activeAssets:protected] => Array ( [script] => Array ( [js_weather0] => 1 [js_weather1] => 1 [inline.fdd212cdd0684aec80324a770a7a7748] => 1 ) ) [locked:protected] => [dependenciesIsActual:protected] => [sortedAssets:protected] => Array ( [script] => Array ( ) )
A small trick that can help.
First, don't forget this:
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
Then:
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('vuejs','mystuff/vue.2.6.14.js', [], ['defer' => true], ['core']);
$wa->registerAndUseScript('myvuescriptname','mystuff/myvuescript.js', [], ['defer' => true], ['core']);
$wa->useScript('myvuescriptname');
Don't use $wa = Factory::getApplication()->getDocument()->getWebAssetManager();
if it's not really needed (for example in the view you can use $this->getDocument()....)
Also You don't need $wa->useScript();
because you use registerAndUseScript already.
@jschmi102 I tried to make your comment more readable but didn't was really successfully, can you repost with correct styling and maybe not use print_r instead use var_dump or at least pretty copy-paste please.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-09-24 13:16:49 |
Closed_By | ⇒ | jschmi102 |
hi,
what do you think?
If you have an application which runs perfectly with 5 systems and does not wit one singel system. Woluld you think the application is the problem orr the failing system?
So I did the most reasonable: I used a working backup/restore of the failing sytem. And what happened? My extension is working now on this system.
From the limited information you have provided it is impossible to debug why your extension does not work on a specific site and does work on other sites