0

I am writing PHP API for Joomla3.9 website where I need to deliver the HTML produced by mod_articles_category modules. I tried blow code to get Module HTML output but it does not working any more It shoiwng the erro someting like that "Call to a member function get() on null"

define('_JEXEC', 1); 
include_once DIR . '/defines.php';
require_once JPATH_BASE . '/includes/defines.php'; 
require_once JPATH_BASE . '/includes/framework.php'; 
$app      = JFactory::getApplication('site');

jimport('joomla.application.module.helper'); 

$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module'); 
$module   = JModuleHelper::getModule('mod_articles_category', 'Module title I used here'); 

echo $renderer->render($module); 

?> 

Basically I need this module HTML output in the same way as it render on Joomla pages so that I can send this out to REST API user. It showi

Please suggest me

4
  • Please describe exactly how it doesn't work anymore. This is essential in a complete question. Are you seeing errors? Blank screen? Mangled output? Some volunteers will already know, but it makes your question higher value to express what isn't working properly. Commented Dec 28, 2018 at 4:51
  • This is my complete php code define('_JEXEC', 1); include_once DIR . '/defines.php'; require_once JPATH_BASE . '/includes/defines.php'; require_once JPATH_BASE . '/includes/framework.php'; $app = JFactory::getApplication('site'); jimport('joomla.application.module.helper'); $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $document = JFactory::getDocument(); $renderer = $document->loadRenderer('module'); $module = JModuleHelper::getModule('mod_articles_category', 'Module title I used here'); echo $renderer->render($module); ?> Commented Dec 28, 2018 at 5:01
  • It showing not a blank page only Commented Dec 28, 2018 at 5:04
  • Please edit your question, then delete your comments. Commented Dec 28, 2018 at 5:07

1 Answer 1

0

Use JModuleHelper::renderModule($module) instead of $renderer->render($module) also add code in your question along with the value of $module object, so we can understand your issue better and provide solutions accordingly.

2
  • I tried your code it showing error Call to a member function getTag() on null Commented Dec 28, 2018 at 18:03
  • Your API called for this code is directed from controller or accessing a file directly? As you are loading the framework. If you are redirected from the controller framework will be included already, in your case you will not be receiving any value in the $module, it may be due to the framework or any dependent file not included properly.
    – Pratyush
    Commented Jan 2, 2019 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.