PHP
Joomla! 6
Joomla! 5
Joomla! 3 (Legacy)
Template Override
Intermediate
Render Modules from Any Position Anywhere in Joomla
Loads and renders every published module assigned to a custom position inside overrides, components or templates.
templates/seu_template/html/com_content/article/default.php
<?php
declare(strict_types=1);
use Joomla\CMS\Helper\ModuleHelper;
$position = 'contato-direita';
$attribs = ['style' => 'html5'];
$modules = ModuleHelper::getModules($position);
foreach ($modules as $module) {
echo ModuleHelper::renderModule($module, $attribs);
}
Uses namespaced ModuleHelper with native Joomla 5 and 6 html5 chrome.
templates/seu_template/html/com_content/article/default.php
<?php
jimport('joomla.application.module.helper');
$position = 'contato-direita';
$attribs = array('style' => 'xhtml');
$modules = JModuleHelper::getModules($position);
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module, $attribs);
}
Legacy Joomla 3 version using jimport and JModuleHelper.
Technical explanation and best practices
Whenever you want to inject a module position (such as sidebar-cta or article-inline) directly inside an article override, category layout or custom component, pair ModuleHelper::getModules() with ModuleHelper::renderModule().
Prefer the modern html5 or none module chrome in Joomla 5 and 6 instead of legacy xhtml.