I am building a module to display other modules if certain checks are passed, and I am having trouble creating the output.
In html, a module is called using <jdoc:include type="modules" name="user1" style="xhtml" />. However in php this does not work. So I am trying to find the class and the precise code to output modules from the php code of my module.
Amongst the ways I tried to output the modules to be displayed is to include a file containing a module call like there would be in a template, and following the way mod customcode creates output. With the 1.0.x version of my module I successfully did so following the example of mod php, but in Joomla 1.5 this does not work.
I also had a look at MetaMod, another 1.5 compatible module to display other modules. I suppose I could imitate the way it is done by MetaMod but in the code I found a comment "// do some stuff that is found in libraries/joomla/application/module/helper.php". This made me think that it seems pointless copying stuff from classes that already exist instead of just using the right class. Unfortunately however I have not been able to prove my point yet.
The latest thing I tried in vain, after a lot of researching, was as follows:
if ($callmoap==1) { //all checks ok so modules should be displayed
if ($moap_displayname) { //display module by name
$document =& JFactory::getDocument();
jimport( 'joomla.document.renderer' );
jimport( 'joomla.document.html.renderer.modules' );
$renderer = new JDocumentRendererModules( $document );
echo $renderer->render( $moap_displaypos );
} else { //display modules by position
$document =& JFactory::getDocument();
jimport( 'joomla.document.renderer' );
jimport( 'joomla.document.html.renderer.module' );
$renderer = new JDocumentRendererModule( $document );
echo $renderer->render( $moap_displayname );
}
}
Is JDocumentRendererModule(s) the right way to go? If so, have I made a mistake in the code? If not, where should I look for a solution?
A second question is about the style: I have not found information yet on whether and how I can put in the module style. If the above had worked I would have tried echo $renderer->render( $moap_displayname, $moap_displaystyle );, where $moap_displaystyle would be something like xhtml.
I hope someone can help!
rendering modules from php
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
Re: rendering modules from php
I solved it, and I thought it would be nice to post the solution for the next perosn to try this...
In the params of the module's xml file I have this:
Then in the module's php I have the following:
In the params of the module's xml file I have this:
<param name="moap_display_pos" type="text" default="onanypage" label="MODULE POSITION LABEL" description="MODULE POSITION DESCRIPTION" />
<param name="moap_display_name" type="text" default="" label="MODULE NAME LABEL" description="MODULE NAME DESCRIPTION" />
<param name="moap_display_style" type="list" default="-2" label="MODULE DISPLAY STYLE LABEL" description="MODULE DISPLAY STYLE DESCRIPTION">
<option value="">SET STYLE</option>
<option value="table">VERT</option>
<option value="horz">HORZ</option>
<option value="none">OUTLINE</option>
<option value="xhtml">XHTML</option>
<option value="rounded">ROUNDED</option>
</param>
Then in the module's php I have the following:
$moap_displaypos = $params->get( 'moap_display_pos' );
$moap_displayname = $params->get( 'moap_display_name' );
$moap_displaystyle = $params->get( 'moap_display_style'. '' );
$moap_divspace = $params->get( 'moap_divspace' );
$moap_cleardiv = $params->get( 'moap_cleardiv' );
if ($moap_displayname) {
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = "";
foreach (JModuleHelper::getModule($moap_displayname) as $mod) {
$attribs = array();
$attribs['style'] = $moap_displaystyle;
$contents .= $renderer->render($mod, $params);
}
echo $contents;
}
if ($moap_displaypos) {
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = "";
foreach (JModuleHelper::getModules($moap_displaypos) as $mod) {
$attribs = array();
$attribs['style'] = $moap_displaystyle;
$contents .= $renderer->render($mod, $attribs);
}
echo $contents;
}
Re: rendering modules from php
Thanks dude, you saved the day!!
http://www.JBookmarks.com - Submit your Joomla site. Vote on other joomla sites! Or just a great place to find Joomla specific resources.
Re: rendering modules from php
Thanks, well, half a day I think; I still haven't managed to get the module by name part of the php file to work...
Re: rendering modules from php
Hi,
I have written a similar component in 1.5, that loads in various modules, but I have not found a good way to pull in each of the separate module's params (defined in their XML and configurable through the Module Manager). Once I render the module, I have no access to the params (nor request variables)....
Any suggestions on how to do this? I'm highly clueless here..
Thanks, Mark
I have written a similar component in 1.5, that loads in various modules, but I have not found a good way to pull in each of the separate module's params (defined in their XML and configurable through the Module Manager). Once I render the module, I have no access to the params (nor request variables)....
Any suggestions on how to do this? I'm highly clueless here..
Thanks, Mark
Re: rendering modules from php
I suppose it would be too much to post here, but if you want feel free to send some files for me to see if I can find the issue.