Control modules based on selected Joomla template

(6 votes, average 4.33 out of 5)

Joomla lets you display different pages on your site with different templates. Unfortunately this can play havoc with your modules, because different templates put the different modules positions on different parts of the page, or call them different names. These recipes will help you to hide or change certain modules if the page is displayed on certain templates, etc.

The MetaMod can only be attached to one module position at a time. Therefore, if you want a module to appear in one module position in one template, and another module position in another template, they you will need to set up a MetaMod in each of the module positions – in one, set the rule to display the module if you are using the “X” template, and in the other, set the rule to display the module if you are not using the “X” template. The following two recipes may help.

Only show a module in the current position when using the “rhuk_milkyway” template:

$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
if ($template == "rhuk_milkyway") return 101; /* on this template, use module 101 */

Show the given module in this position on every template except “rhuk_milkyway”:

$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
if ($template != "rhuk_milkyway") return 101; /* on all other templates, use module 101 */