Joomla Module placement in Articles, Categories or Templates

Sometimes we need to place a module in between our Article or Category text, or render a module outside of the index.php file. Joomla is very flexible and enables us to position the modules where we need it, we just have to know how.

There are multiple ways on how to include modules in different views and inside texts. Depending on where we want the modules to be placed we have the following options:

  1. load a module position with {loadposition} inside Article or Category text,
  2. load a specific module with {loadmodule} inside Article or Category text,
  3. load a module or module position inside our template .php files in different views.

If the loadposition and loadmodule does not work

When using the {loadposition} or {loadmodule} you have to be certain that the text is echoed through $this->item->introtext or $this->item->text. I was pulling my hair out wondering why the modules didn’t appear. It seems that Joomla does not allow loading the modules if the text in the template is echoed with $this->item->fulltext.

Also the name of the position has to be lowercase and the plugin Content – Load Module has to be enabled.

Using Joomla loadposition to output modules in article or category text

If we need to output a specific module position inside our Article or Category text the position must not be present inside the templateDetails.xml file! We need to create an “empty” position, making up a name in the module position an pressing Enter. Place the bellow code anywhere inside the text. For the category text be sure that it’s enabled to display in the menu item settings.

{loadposition nameOfThePosition}

Using Joomla loadmodule to load a specific module by type or name

Loading the module can accept the following parameters:

{loadmodule moduleType, moduleName, moduleChromeStyle}

If we wanted to load a login module with a specific name we would do it like this:

{loadmodule login, This is the title of the module}

The moduleType parameter is the folder name of the module without the mod_ prefix. You can read more in the official Joomla docs.

Output a module position inside a template override file

If we need to show the modules inside the template index.php file we won’t have any issues with the standard joomla <jdoc:include type=“modules”>. But if we are outside the index file, i.e. in a template article or category layout override, we need to call them in a different way (tnx to Phil Locke, who showed me the code):

// Render modules inside this article override
$doc      = JFactory::getDocument();
$renderer = $doc->loadRenderer(“modules”);
$raw      = array(“style” => “standard”);

// Echo the module somewhere in the template
<?php echo $renderer->render(“module-position”, $raw, null); ?>