I have a system plugin. Previously in 3.x the plugin initiated in the onAfterRoute event. In this event, the plugin attaches scripts/styles to the document and finally render the HtmlDocument like
$doc->render(false, ['template' => 'mytemplate', 'file' => 'component.php'])Now for converting to the J4 beta I need to register and use styles/scripts using WebAssetManager. But attaching assets at the onAfterRoute event says-
Call to a member function getWebAssetManager() on nullAnd also in some events says that the "WebAssetManager is locked, you came late" something like this.
So my question is, at plugins where to Register and Use WebAssets and where not to.
Note: I don't want any template-specific assets i.e. any assets from atum or cassiopeia. I just need my own assets and own HTML to render after hitting a specific route.
| Labels |
Added:
?
|
||
In normal runtime the asset can be registered between onAfterRoute and onBeforeCompileHead.
But preferable between onAfterDispatch and onBeforeRender
I've registered the assets at the onAfterDispatch event. But cannot use this
$doc->render(false, []);method instead I've used
$doc->setBuffer($content, 'component');And for rendering the the component.php file instead of the index.php file I've just set the input tmpl=component at the onAfterRoute event like-
Factory::getApplication()->input->set('tmpl', 'component');And now it's working.
I suspect you have override joomla Document and some other classes, that why it not worked.
Please close the issue if it fixed.
| Status | New | ⇒ | Closed |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-10-07 10:12:35 |
| Closed_By | ⇒ | ahamed |
You doing something hacky.
And that the result.
In normal runtime the asset can be registered between onAfterRoute and onBeforeCompileHead.
But preferable between onAfterDispatch and onBeforeRender