使用我的 Joomla 插件,我想在创建输出之前获取并修改所有内容。
function newContent($html)
{
$html = "new content";
return $html;
}
function onContentPrepare()
{
ob_start(array($this, "newContent"));
return true;
}
function onContentBeforeDisplay()
{
ob_end_flush();
return true;
}
我尝试使用 onContentAfterDisplay
但它只会继续更改一小部分,而不是所有输出。
最佳答案
你为什么不这样做:
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
$article->text = "new content";
}
?
编辑
根据您的回复,这是一种在插件中修改整个页面内容/正文的方法。将此方法添加到您的插件中:
public function onAfterRender()
{
$app = JFactory::getApplication();
$currentBodyToChange = $app->getBody();
//do something with $currentBodyToChange
//$bodyChanged is modified $currentBodyToChange
$app->setBody($bodyChanged);
}
关于php - Joomla 插件在输出前获取整个页面的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31891678/