2015-08-08 61 views
3

使用我的Joomla插件,我想在创建输出之前获取并修改所有内容。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但它仍然只改变一小部分,而不是所有的输出。

回答

2

为什么你不只是做:

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); 
} 
+0

嗨,我想获得和修改所有内容(头,体,尾),所有的页面,不仅文章 –

+0

@Vasile亚历喜兽疫,我我更新了我的答案。 – arbogastes

+0

嗨,它的工作原理,谢谢。 –