jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('module_name');
echo $module;
{"id":"93","title":"contact","module":"mod_module_name","position":"position-7".........
null
Joomla 3.9, Apache/2.4.34 (Unix), mySQL 8.0.12
Labels |
Added:
?
|
The name should include
mod_
prefix:JModuleHelper::getModule('mod_module_name')
.
I try that also and then I got fallowing result:
{"id":"0","title":"","module":"mod_module_name","position":"".........
In Joomla 3.7.3 everything was working with "mod_" or without prefix.
Just tried with prefix and without. Works both ways in 3.9.0. But in case no module with specified type is published (looking at 0 ID in your result), you must use the prefix to get a new module object. The same is true in 3.7.3.
Actually, it is a bug, but it's not related to a version of Joomla. This bug is related to module settings, exactly with module assignment.
If you select to show module on "All pages" or if you select to show module on "On all pages except those selected" everything work as it should, but if you select to show module on "Only on the pages selected", then you will get strange behaver as I mention above.
Depending on the Joomla version you got different strange behaver. On ver. 3.9 you got an output as I wrote above ({"id":"0","title":"","module":"mod_module_name","position":"".........), but for example in ver. 3.8 you got this message. "Module mod_module_name is not published, you do not have access to it, or it's not assigned to the current menu item."
Could you please provide a clear step-by-step instruction for a situation where it works and a situation where it doesn't work but should work inclusive code snippets for rendering the modules.
An echo
like in your first post never rendered a module.
Status | New | ⇒ | Closed - Unconfirmed Report |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-12-20 03:33:10 |
Closed_By | ⇒ | Quy |
Status | Closed - Unconfirmed Report | ⇒ | Closed |
Closed_By | Quy | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/23105
This can be reopened when the requested information is provided.
I am trying to render a mod_login module - on the fly - through a plugin. So far, there is no existing mod_login instance in the website. I am just trying to create a new object through php.
$module = JModuleHelper::getModule('mod_login', '');
$moduleParams = new JRegistry($module->params);
$moduleParams->set('style', "System-html5");
$module->showtitle = "1";
$module->title = $title;
$renderer = $doc->loadRenderer('module');
$modHtml = $renderer->render($module, array('params'=> $moduleParams));
On my MAMP localhost php72, it works. On the online server (Litespeed - php72) it doesn't. I have to create a login module and specifically select that one in order to render it: $module = JModuleHelper::getModule('mod_login', 'My Login');
Joomla 3.9.19 in both systems.
I can't figure out why
Why did you close this issue??
I've spent four hours trying to figure out what mistake I made and then I read that there is a bug!
I had my custom module "Only on the pages selected". Thankfully there is a workaround as mentioned by nedjic
Why did you close this issue??
Meanwhile we're on Joomla 3.10 and I still can not confirm the issue. i don't see a "bug". Just expected bahavior from my point of view.
ModuleHelper::getModule('mod_login')
returns just 1 if there are several.defined('_JEXEC') or die;
use Joomla\CMS\Helper\ModuleHelper;
$module = ModuleHelper::getModule('mod_login');
echo ' Debug module: <pre>' . print_r($module, true) . '</pre>';exit;
Module Assignment: No pages
stdClass Object
(
[id] => 0
[title] =>
[module] => mod_login
[position] =>
[content] =>
[showtitle] => 0
[control] =>
[params] =>
)
=> Expected. Not assigned. Therfore just an empty dummy.
Module Assignment: On all pages
stdClass Object
(
[id] => 44
[title] => Login
[module] => mod_login
[position] =>
[content] =>
[showtitle] => 1
[params] => {"pretext":"","posttext":"","login":"280","logout":"280" ...}
[menuid] => 0
[name] => login
[style] =>
)
=> Expected. Assigned. Therfore the full module data.
Module Assignment: Only on selected ... and assign Home menu.
Module Assignment: Only on selected ... and DO NOT assign Home menu
but some other.Module Assignment: On all except selected ... and DO NOT assign Home menu
but some other.Module Assignment: On all except selected ... and assign Home menu
.Trash and delete all modules of type "Login"
.An additional:
echo ModuleHelper::renderModule($module);
populates the $module->content with the login form and outputs something like:
The name should include
mod_
prefix:JModuleHelper::getModule('mod_module_name')
.