Load Module in custom Component.

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
User avatar
bohn002
Joomla! Guru
Joomla! Guru
Posts: 753
Joined: Thu Aug 18, 2005 6:14 pm
Location: Ohio-USA

Load Module in custom Component.

Post by bohn002 » Wed Sep 10, 2008 5:29 pm

Trying to load a module into a custom, non-article related component. I tried adding to my component.

Code: Select all

jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('modulename');
echo JModuleHelper::renderModule($module);
I replaced 'modulename' with both the title of the module and the mod_module name and nothing was loaded.

i even tried

Code: Select all

function plgContentLoadPosition( $position, $style=-2 )
    {
      $document   = JFactory::getDocument();
      $renderer   = $document->loadRenderer('module');
      $params      = array('style'=>$style);
      $contents = '';
      foreach (JModuleHelper::getModules($position) as $mod)  
      {
         $contents .= $renderer->render($mod, $params);
      }
      return $contents;
   }
with

Code: Select all

plgContentLoadPosition('right');
in the body of the component.

So nothing is working, I am trying to load the position 'demo' off a custom html module. How can I do this?
remember pillage...then burn.

DeZzL
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Fri Jun 02, 2006 12:37 pm
Contact:

Re: Load Module in custom Component.

Post by DeZzL » Tue Sep 23, 2008 10:12 am

bohn002 wrote:*snip
I'm trying to achieve the same thing. Have you had any success with this bohn002?

User avatar
bohn002
Joomla! Guru
Joomla! Guru
Posts: 753
Joined: Thu Aug 18, 2005 6:14 pm
Location: Ohio-USA

Re: Load Module in custom Component.

Post by bohn002 » Tue Sep 23, 2008 3:10 pm

nope, have yet to find anything else.
remember pillage...then burn.

its_possible
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Oct 24, 2008 1:29 pm
Contact:

Re: Load Module in custom Component.

Post by its_possible » Fri Oct 24, 2008 1:34 pm

hi

It can be done this way

Code: Select all

/*************************************************
* Added by sameer to load module find_a_story in this component
 */ 
//jimport('joomla.application.module.helper');

$modules = JModuleHelper::getModules('find_a_story');
foreach( $modules As $mod ){
	echo  $mod->content;
}
/*************************************************/
you can use $mod->title as well

this is not a perfect approach but at least works for me

-sameer
http://possible.in

sydore
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat May 29, 2010 4:24 pm

Re: Load Module in custom Component.

Post by sydore » Thu Sep 23, 2010 1:08 am

Hi guys!

This work for me:
jimport('joomla.application.module.helper');
// this is where you want to load your module position
$modules = JModuleHelper::getModules('header');
foreach($modules as $module)
{
echo JModuleHelper::renderModule($module);
}

User avatar
sn00ze
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Wed Jul 15, 2009 11:01 am
Contact:

Re: Load Module in custom Component.

Post by sn00ze » Thu Feb 24, 2011 1:18 pm

sydore wrote:Hi guys!

This work for me:
jimport('joomla.application.module.helper');
// this is where you want to load your module position
$modules = JModuleHelper::getModules('header');
foreach($modules as $module)
{
echo JModuleHelper::renderModule($module);
}
thanks, this worked for me!

User avatar
sakiss
Joomla! Explorer
Joomla! Explorer
Posts: 349
Joined: Wed Aug 20, 2008 4:09 pm

Re: Load Module in custom Component.

Post by sakiss » Fri Jun 10, 2011 3:17 pm

Oh sn00ze really thank you!

KaozDesigns
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Nov 21, 2011 2:16 pm

Re: Load Module in custom Component.

Post by KaozDesigns » Mon Nov 21, 2011 2:33 pm

Totally love you for this sn00ze.

jmarinier2
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Dec 07, 2011 7:29 pm

Re: Load Module in custom Component.

Post by jmarinier2 » Wed Dec 07, 2011 7:35 pm

Hi everybody,

to answer the initial post, this is the correct way use getModule it in Joomla 1.7, you need 2 parameters:

Code: Select all

jimport('joomla.application.module.helper');
	$module = JModuleHelper::getModule('mod_yourmodulename','YourModuleTitle'); 

	echo JModuleHelper::renderModule($module);
The module called doesn't need to be inserted in a position, I just published it.

But thanks anyway, this thread showed me the way to find the answer, hope this helps others :)

DrDigital
Joomla! Apprentice
Joomla! Apprentice
Posts: 35
Joined: Mon Dec 10, 2007 9:51 pm
Location: Stockton Ca
Contact:

Re: Load Module in custom Component.

Post by DrDigital » Mon Feb 06, 2012 9:19 am

I got a trickier one... How do I load a module thats got advanced parameters and alternative layouts?

I got the module showing... but its not the correct view
You do not have the required permissions to view the files attached to this post.

jakabadambalazs
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Mar 15, 2012 2:26 pm

Re: Load Module in custom Component With Parameters

Post by jakabadambalazs » Thu Mar 15, 2012 2:39 pm

DrDigital wrote:I got a trickier one... How do I load a module thats got advanced parameters and alternative layouts?
I got the module showing... but its not the correct view
I had the same question - so I looked at the JModuleHelper class in:
libraries/joomla/application/module.helper.php

..and if you check out the function that renders the module - the one you are calling passing it the $module - you'll find this line:
// Get module parameters
$params = new JParameter( $module->params );

So I thought well, I'll give you the params on the module object - but the tricky thing is: what is $params should be array? object? ... o I opened the JParameter class and as it seems to me the only way is to pass it the raw params as a string where each key=value pairs are separated by a newline "\n"

And it works!
Maybe there are other ways but this is quite easy - here is the code:

Code: Select all

 
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('mod_mymodule','MY MODULE NAME');
$mP = array();
$mP[] = "moduleParamName1=value1";
$mP[] = "moduleParamName2=value2";
$mP[] = "moduleParamName3=value3";
$module->params = implode("\n", $mP);
$moduleHtml = JModuleHelper::renderModule($module);
echo $moduleHtml;
The know what are the names and values that you can use for a certain module, open its xml file (u know that).

BTW - this is J!1.5 stuff - I'm still stuck here

polpaulin
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 158
Joined: Wed Dec 22, 2010 12:00 pm

Re: Load Module in custom Component.

Post by polpaulin » Sat Mar 17, 2012 10:22 am

jmarinier2 wrote:Hi everybody,

to answer the initial post, this is the correct way use getModule it in Joomla 1.7, you need 2 parameters:

Code: Select all

jimport('joomla.application.module.helper');
	$module = JModuleHelper::getModule('mod_yourmodulename','YourModuleTitle'); 

	echo JModuleHelper::renderModule($module);
The module called doesn't need to be inserted in a position, I just published it.

But thanks anyway, this thread showed me the way to find the answer, hope this helps others :)
how can you do the same thing with an article ?

something like
echo JArticleHelper::renderArticle($article);

thank you

MAtkins
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Wed Apr 11, 2012 7:22 pm

Re: Load Module in custom Component.

Post by MAtkins » Fri Aug 31, 2012 4:04 am

Over and over, I ask questions here and look up answers and get nothing or the 'dodge' meaning they refer to other links that don't help or provide solutions that don't work.
I had about given up on this forum.

Here were multiple solutions, the best I think were from polpaulin.
Thank You!!
I tried it in version 2.5.
That works like a charm pretty much anywhere I have server side code!!

dwrightsnap
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Wed Jan 25, 2012 2:40 pm

Re: Load Module in custom Component.

Post by dwrightsnap » Thu Jun 20, 2013 8:04 pm

I tried all the methods here without any success in 3.1. Anybody got any tips?

dwrightsnap
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Wed Jan 25, 2012 2:40 pm

Re: Load Module in custom Component.

Post by dwrightsnap » Thu Jun 20, 2013 8:09 pm

Just kidding, jmarinier2's works, module style was just set to "none"...


Locked

Return to “Joomla! 1.5 Coding”