Sign up to our newsletter to receive notifications of extension updates.

Friday, 24 December 2010 00:19

Getting Joomla modules to appear on the right pages

Written by 
The idea of modules is one of the more difficult concepts behind Joomla and it can take quite some time to master them. There is, however, an issue that most people will run into at somepoint or another - how to get modules to show up on specific pages. The basic functionality allows the user to select the modules to appear on certain menu items and their child items but this is the extent of it.

What happens, for example, if we want to display a module with a poll in it but only when one particular article is being read. This is not possible when using the basic options as we can only assign to entire menu items at a once. So what do we do? There is an extension called Advanced Module Manager that greatly increases flexibility when assigning modules to certain pages. Instead of just assigning modules to menus it gives you the option of assigning them based on many different criteria.

  • Menu Item
  • Sections / Categories
  • Articles
  • FLEXIcontent Categories
  • K2 Categories
  • Mighty Resource Categories
  • ZOO Categories
  • Components
  • URL
  • Date
  • User Group Levels
  • Users
  • Languages
  • Templates
  • PHP evaluation

For the scenario I described above we could assign the module based on one article. However, the most interesting of these is the PHP evaluation criteria. This option gives us unlimited scope regarding when our modules are displayed. All we need to do is create the PHP code to make it work. For example, let's say we want a module to appear on the "Thank you" page only. The URL of this page is going to be something along the lines of To work out whether or not the user is on this page we need to do a regular expression match on the URL.
$pattern = '/[a-z|0-9]{32}/';
$string = $_SERVER["REQUEST_URI"];
The preg_match will return a match if the REQUEST_URI variable has a 32 length alphanumeric string in it, preceded by "activation=". We can now assign our module based on this criteria.
Read 10719 times Last modified on Friday, 24 December 2010 01:22