Search code examples
modulejoomlacomponents

How can I display Joomla modules within a component?


I have a component with several categories of games and I want to display a different banner depending on the category. I need the banner (and link) to be customizable so it's not simply a case of showing categoryX.jpg or whatever.

I saw this Joomla help page on another question, but it only seems to display a module type, not one specific module. I'd like to use various mod_custom modules and display the one appropriate to the category (I can store each module's ID if necessary).

Any ideas?


Solution

  • This can be done in a 2 step process:

    1. Use the "Load module into article" plugin to allow yourself to access the module using a plugin call like:

      {module [*mod_id*]} // where *mod_id* is the module id

    2. Now that you can call a plugin to put your module anywhere, you now need to go to the view code of your/a component you wish to add the module to and add this code:

      echo JHTML::_('content.prepare', '{module [*mod_id*]}');

    Please see this link - http://www.alltogetherasawhole.org/group/developers/forum/topics/running-joomla-content-plugins - regarding point number 2. I was trying to do the same thing and I found it didn't work, and the reason for this was a comment you can find on the page link above:

    "I noticed that some plugin actually expect option=com_content for them to process onPrepareContent properly, so you might actually want to "fool" them by callin JRequet::setVar and restoring the correct values after the trigger."