Joomla comes with a method to load a module into an article: the loadModule content plugin. This plugin can be used with Joomla core articles, but also most components will support content plugins. For example Virtuemart will allow content plugins in the product description, provided you allow this option in the Virtuemart configuration, making a handy way to load a module into the product details page. Custom HTML modules will also support content plugins, making it possible to load a module inside another module. It also raises the intriguing possibility that you can have a module that embeds itself.
The LoadModule plugin works through some very simple embedding code, which is replaced by the actual module when Joomla renders the article. The code has two alternative forms:-
{loadposition positionname}
{loadmodule modulename}
where positionname is replaced by an actual module position, and modulename is replaced by an actual module name.
To see how this works, first create a module through the Joomla module manager. If you just want to test the system this can be a custom HTML module, call it test module and put some arbitrary text in it. Now we will look at embedding this module in an article. If you are not planning to display the module anywhere else a useful way to tackle this is to assign the module to a custom position name (one not used in your template), for example embed1. Make sure that the module is assigned to display on all pages. Then put the following code in a Joomla article:-
{loadposition embed1}
If you view the article you should now see the module output displayed in place of the embedding code. If you just see the code, check that the LoadModules plugin is enabled in the Joomla plugin manager.
The {loadmodule} syntax usage is similar, though there are a couple of points to be aware of. You need to use the module name to select the module to display. For 3rd party extensions this will be the module type name that you see in the Joomla module manager (eg K2 Content), so it is quite easy to find the name, however for Joomla core modules this will be the system name, for example 'mod_custom' in the case of the Custom HTML module. If you are having problems finding the correct name to use and you have access to your database admin you can find out the correct module name by examining the 'extensions' database table. We give a list of the core Joomla module names at the bottom of this article.
If you use the syntax such as
{loadmodule mod_custom}
the plugin will output the first custom HTML module that it finds which can be displayed on the page. Often you will not want this, so you can supply the module title as an additional parameter in the embedding code:-
{loadmodule mod_custom,Test Module}
In this case the plugin will find the custom HTML module with the title 'Test Module' - the one we created earlier.
For example, suppose you create a custom HTML titled 'Test Module', with the following content:-
This is the module output
{loadmodule mod_custom,Test Module}
When Joomla tries to render the module does this create an inconsistency in the space-time continuum, and cause us all to cease to exist? Fortunately, no. If you then embed this module in an article you will just see the module output ('This is the module output'). If you display the module in a normal Joomla module position you will see the module output ('This is the module output') rendered twice.