简体   繁体   中英

Joomla plugin get contents of whole page before output

With my Joomla plugin I would like to get and modify all the contents before the output is created.

function newContent($html)
    {
    $html = "new content";
    return $html;
    }

function onContentPrepare()
    {
    ob_start(array($this, "newContent"));
    return true;
    }

function onContentBeforeDisplay()
    {
    ob_end_flush();
    return true;
    }

I tried with onContentAfterDisplay but it continues to change only a small piece and not all the output.

Why won't you just do:

public function onContentPrepare($context, &$article, &$params, $page = 0)
{
     $article->text = "new content";
}

?

EDIT

Basing on your response, here is a way to modify whole page content/body in plugin. Add this method to your plugin:

public function onAfterRender()
{
    $app = JFactory::getApplication();
    $currentBodyToChange = $app->getBody();

    //do something with $currentBodyToChange
    //$bodyChanged is modified $currentBodyToChange

    $app->setBody($bodyChanged);
}

To stop a plugin firing on the admin pages...

$app = JFactory::getApplication();
if ($app->isSite())  echo 'Front end - do it!';
if ($app->isAdmin()) echo 'Admin pages - ignore!';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM