phpmodulejoomlajoomla1.7

can I use joomla's onAfterRender for a module rather than a plugin?


I want to insert some code to Joomla when any page is loaded.

For this I created a module that inserts code.

I am trying to use

<?php 
// $Id: helper.php

defined('_JEXEC') or die;
jimport( 'joomla.plugin.plugin' );
jimport( 'joomla.environment.response' );

class modInsertCode
{

    function onAfterRender($params)
    {
            $code = 'some code'; 

            $documentbody = JResponse::getBody();
            $documentbody = str_replace ("</body>", $code." </body>", $documentbody);
            JResponse::setBody($documentbody);

            return true;

    }

}
?>

but JResponse::getBody(); returns an empty string. Any ideas, solutions of fixes to this code?

Thank you,


Solution

  • You have to do it using a plugin, you won't be able to do it using a module because the HTML response has not been generated by the time the code of the module gets executed.

    I hope it helped!