EVENT-AFTERRENDER-001
onAfterRender() { $body = JResponse::getBody(); }
onAfterRender HTML string hacks
JResponse body swapping is Joomla 3. Joomla 4+ will surprise you with compressed output and split assets.
onAfterRender() { $body = JResponse::getBody(); } → Document events / WebAssetManager
What you will see
- Class "JResponse" not found
Symptoms people search
script inject plugin broken · onAfterRender · JResponse
Replace this code
Swap onAfterRender() { $body = JResponse::getBody(); } for Document events / WebAssetManager.
Joomla 3
Remove or stop calling this
public function onAfterRender() {
$body = JResponse::getBody();
$body = str_replace('</body>', $js . '</body>', $body);
JResponse::setBody($body);
}Joomla 4 / 6
Use this instead
Add scripts with WAM. If you must mutate HTML, use the document after render APIs — JResponse is gone.How to fix it
- 1Prefer WebAssetManager.
- 2If you still str_replace HTML, test with gzip on.
Also known as
JResponse · onAfterRender · setBody · getBody
There is no 1:1 swap for this one. The architecture changed. If you cannot rewrite it, Infyways can.
Related issues
- Joomla 3 → 4Joomla API
JError / JException
JError::raiseError() → throw new RuntimeException() / try-catch
- Joomla 3 → 4Events / plugins
JDispatcher / JEventDispatcher
JDispatcher::getInstance() → Event dispatcher + SubscriberInterface
- Joomla 3 → 4PHP
each() / create_function() / ereg / split
each($array) → foreach / closures / preg_*
- Joomla 5 → 6Events / plugins
JPlugin onX methods vs SubscriberInterface
function onContentPrepare(...) → CMSPlugin + SubscriberInterface::getSubscribedEvents()
- Joomla 3 → 4PHP
eval() in extensions
eval($code) → Never — forbidden for Infyways work
- Joomla 5 → 6Events / plugins
Core plugin event names (J3 methods → subscribers)
onContentPrepare / onAfterDispatch / … → SubscriberInterface::getSubscribedEvents()