rendering modules from php
Posted: Wed Feb 13, 2008 8:16 am
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!
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!