DisgruntledGoat
DisgruntledGoat

Reputation: 72510

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?

Upvotes: 2

Views: 9745

Answers (5)

Mohd Abdul Mujib
Mohd Abdul Mujib

Reputation: 13908

You can also use the Joomla Module Renderer

$doc = JFactory::getDocument();
$renderer = $doc->loadRenderer('modules');
$position = 'custom_position_name';
$options  = array('style' => 'raw');
echo $renderer->render($position, $options, null); 

Just a heads up, Along with being assigned the module position, that module also has to be set to "Display on All pages".

Upvotes: 1

Umesh
Umesh

Reputation: 193

If you would like to show module within PHP code then use this code, it's worked for me :

<?php echo   JHTML::_('content.prepare', '{loadposition position-2}');  ?>

If you want to show module inside html content then just put this code where you want to show module.

{loadposition position-2}

It loads all modules which are assigned to position-2.

Upvotes: 3

Brent Friar
Brent Friar

Reputation: 10609

Joomla has this functionality built in. You can use the {loadposition XX} command within your content items. You can specify custom module positions that do not appear in your template to insure that you have the correct module in the correct article.

http://docs.joomla.org/How_do_you_put_a_module_inside_an_article%3F

Upvotes: 0

Martin
Martin

Reputation: 10563

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."

Upvotes: 5

Jeepstone
Jeepstone

Reputation: 2601

You could create a new module?

If each category appears in the querystring (catid=X) then you could take a similar approach to https://support.pillwax.com/open-source/doku.php?id=joomla:header_image.

Alternatively, that link might actually do it for you.

Upvotes: -1

Related Questions