Re: [jgen] creating a plugin for Joomla 4

32 views
Skip to first unread message
Message has been deleted

seraphim

unread,
May 3, 2021, 4:58:19 AMMay 3
to joomla-de...@googlegroups.com
I just had a quick look but you are mixing javascript and php code wrong. Your addScriptDeclaration should be like:
'window.event("domready", function()...  const data=document.querySelectorAll("h1,h2,h3,h4,h5,h6")[i].innerHTML = "' . $result . '" + document.querySelectorAll("h1,h2,h3,h4,h5,h6")[i].innerHTML ;

Hope this would help.

Op 03-05-2021 om 10:46 schreef Devika Harshan:
 I am trying to develop a plugin for Joomla 4  and it's my first time doing it.  Can you guys please give a look at the code ?

The speciality of this plugin is that ;
  •  It should only be executed in the backend.
  •  It includes a text parameter field.
  •  In case the plugin is activated the plugin should inject Javascript which attach the text from the parameter field described in point b into each headline.

Rewording that:

If the plugin is published, the plugin should use Javascript to inject the text provided in the parameter field into each headline.So if the parameter was "Superman" and the headline was "Leaps tall buildings" then the plugin would result in the headline becoming "Superman Leaps Tall Buildings" when the page was displayed and the plugin was published.


please take a look at this code



class PlgSystemappendtext extends CMSPlugin implements SubscriberInterface

{
public function onAfterDispatch(){
function mydatabase(){
$db = JFactory::getDbo();

$query = $db

->getQuery(true)

->select($db->quoteName('texts'))

->from($db->quoteName('plug_table'));

$db->setQuery($query);

$result = $db->loadResult();

}
$document = JFactory::getDocument();

$document->addScriptDeclaration(' window.event("domready", function()

{
var num = document.querySelectorAll("h1,h2,h3,h4,h5,h6").length;
for(let i=0;i<num;i++)
{
const data=document.querySelectorAll("h1,h2,h3,h4,h5,h6")[i].innerHTML = $result + document.querySelectorAll("h1,h2,h3,h4,h5,h6")[i].innerHTML ;

}
}

);');

return true;
}


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/ad44e68a-2d42-4d0a-8f3b-7f1bd2657645n%40googlegroups.com.


Message has been deleted

Devika Harshan

unread,
May 3, 2021, 6:26:52 AMMay 3
to Joomla! General Development
Thankyou sir ,I corrected it like you suggested
Reply all
Reply to author
Forward
0 new messages