Search
Other Sourcerer questions
Forum

No able to use Javascript

Fabio Zignale's Avatar Fabio Zignale
Hello!
This is the first time i'm trying to use Sourcerer inside a custom module with JCE as editor and Javascript coding, i already use Sourcerer without editors inside some template areas for PHP coding, but now i can't make it work.

I trying to create a simple alert using custom module with JCE by this code:
{source}<?php
$document->getAssetManager()->addInlineScript(
'alert(\'This is JavaScript\');',
['position' => 'before']
);
?>{/source}

But the module visualize my full code and return also: 0 Call to undefined method Joomla\CMS\Document\HtmlDocument::getAssetManager()


I'm using J4.1 and Sourcerer 9.2.1PRO, where i'm wrong?
Peter van Westen's Avatar Peter van Westen ADMIN
That's a bug.
The button should insert getWebAssetManager() instead of 'getAssetManager().

This is fixed in the latest dev release:
regularlabs.com/development-releases

But you can manually add the missing 'Web' in the code you have in your content to fix that specific instance.
Please post a rating at the Joomla! Extensions Directory
Fabio Zignale's Avatar Fabio Zignale
Tested the DEV version, works perfect!

Thank you Peter!
Fabio Zignale's Avatar Fabio Zignale
No Peter, seems Sourcerer not yet working perfect: when i insert a JS code Sourcerer DEV still create $document->getAssetManager()->addInlineScript....

I'm going wrong?
Peter van Westen's Avatar Peter van Westen ADMIN
Please try now...
regularlabs.com/development-releases
Please post a rating at the Joomla! Extensions Directory
Fabio Zignale's Avatar Fabio Zignale
Yes, now is perfect!
Thank you again Peter!
Peter van Westen's Avatar Peter van Westen ADMIN
Thanks for testing!
The fix will be included in the next release.
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription