To edit entire HTML output directly, create a system plugin with onAfterRender
event. Use application's getBody()
method to get the content and setBody()
to save the modified content.
defined('_JEXEC') or die;
plgSystemExample
{
protected $app;
public function onAfterRender()
{
if ($this->app->getDocument()->type !== 'html')
{
return;
}
$body = $this->app->getBody();
//do modifications to $body here
$this->app->setBody($body);
}
}
But if the content you want to replace is only inside content items (e.g. shortcodes in articles), create a content plugin with onContentPrepare
event and only modify the article text.