Joomla 1.5: Display modules without assigning a menu item

First, I want to address the inevitable concern, "Joomla 1.6 is out, why worry about 1.5?" Well, I worked on a Joomla 1.0 site last week, and I think that is enough argument to keep focusing on Joomla 1.5 releases for at least a couple of months.

This article touches on the root cause of a previous article that also deals with module loading and menu items. In the earlier article, we discussed that third party SEF components for Joomla 1.5 often assign multiple non-SEF URLs to a single SEF URL. Here is a brief example to review:

SEF Component URL: mysite.com/what-search-engines-want-see

Maps to
1. mysite.com/index.php?option=com_content&view=article&id=43
2. mysite.com/index.php?option=com_content&view=article&id=43&Itemid=43
3. mysite.com/index.php?option=com_content&view=article&Itemid=43&id=43

URLs two and three are obviously the same; they differ only in the ordering of their GET parameters. The first URL is problematic, as it does not include the Itemid parameter. At a glance, this loads the page successfully, since an Itemid is not a strict requirement. However, you will notice that when a page loads without an Itemid, module loading may not meet your expectations. But why do some modules load, and others fail?

Let's walk through a quick example. Download the latest 1.5 release (1.5.22 as I am writing this) from joomla.org. Run the setup and install the sample data. Load the resulting Home page, and on the left menu bar, under "Key Concepts", select "Example Pages".

Joomla 1.5 Sample data home

You should get a page with URL like: "./index.php?option=com_content&view=article&id=43&Itemid=43".

Now edit the URL, and remove the "&Itemid=43" parameter from the end, then load the resulting page. Notice the "Example Pages" side menu disappears. This is a particularly good example for the investigation, as the "id" and "Itemid" values are the same! Let's login to the admin interface and investigate the issue further.

Once in the admin area, proceed to the Article Manager and check the ID:

Joomla 1.5 Article Manager

As the "id" GET parameter suggests, the "Example Pages and Menu Links" article has ID 43. Again, why does taking away the Itemid affect the module loading?

Let's review the module configuration for the Example Pages menu. In the admin area, under Extensions -> Module Manager find the "Example Pages" module and select it. Notice that the Module is configured to display only for particular Menu Selections.

Joomla 1.5 Module edit screen

Knowing that the module only displays for some Menu Selections, we should review the menu items. Staying in the admin area, proceed to Menus -> Key Concepts (remember that we originally selected the "Example Pages" link from the "Key Concepts" menu module on the home page). There we have it! The Menu Item does not have a plain "ID" value like an article, rather it has an ItemID. And the "Example Pages" menu item has ItemID 43.

Joomla 1.5 Menu Manager

To make this clear, when you configure a module position, it either gets assigned to all menus (all ItemIds), or it is assigned to a selection of menus (ItemIds). If you assign a module to all menus, the module loads in a given position without checking for an ItemId value from the URL. However, our problem comes about when you load a page that includes modules which do not display on all menus. In this case, before loading the "Example Pages" module, Joomla validates that the ItemId GET param corresponds to one of the selected Menu assignments in the Example Pages module configuration. When Joomla detects that no ItemId GET param exists, it does not load any modules that are configured to display for selected menu assignments (the "null" value is not present in the array of menu assignments for any of these modules). To further review this functionality, you can try changing the Itemid value in the URL. Use the "Example Pages and Menu Links" page where we started. We originally saw the "Example Pages" module disappear, now try passing "Itemid=42", and notice the menu module is removed (just as it was with an absent Itemid value). Also notice the breadcrumbs changed - since they represent the current location based on the Menu assignment. Try "Itemid=44" and notice that the "Example Pages" module returns, and the breadcrumbs again update to represent the appropriate menu.

After that long explanation of the problem, it is time to get to the point: How do you load a module on a page without assigning a menu item to that page? It is a trick question of sorts, because the most straight forward way to accomplish this task is to create a hidden menu. First, create your nomadic page (this could be a "Thank you for purchasing", "Your request is being processed", or some sneaky easter egg - any page that needs to be available, but that you don't want to be selectable from within your menu system). Let's create a page titled "Thank you" with some Lorem ipsum content. Be sure to create it in Section/Category "Uncategorized".

How do we get the "Example Pages" menu module to display on our "Thank You" page? You can probably load the article with URL "./index.php?option=com_content&view=article&id=46" (unless you added other articles first...). Since you'll be manually adding the link within the content of your site, you could cheat a little, and just piggy-back on an acceptable existing menu. This would look like: "./index.php?option=com_content&view=article&id=46&Itemid=43". Here we are simply telling Joomla that it's loading an article (46) and that the current menu is 43 - even though the user didn't actually click on the menu item with Itemid 43. It's worth noting that using the piggy-back technique on sites with breadcrumbs is rarely desirable, since the breadcrumbs will display content based on whatever menu item you use. Occasionally, you get lucky in the configuration and this technique can still work with breadcrumbs.

While menu piggy-backing might work for your needs, I always feel better creating a distinct menu for these purposes. Let's call it "hiddenMenu". Create your "hiddenMenu" menu, and then add a Menu Item of type Article Layout, using the "Thank You" article. The title can be anything, so long as it is recognizable for you and/or your site administrator (Note that it will be used in breadcrumbs if they are enabled). After creating the menu, note the ItemID value; it will be 53 if you are using a fresh Joomla 1.5 installation and have not added other menu items. Once we have a menu item for our "Thank You" article, let's return to the "Example Pages" module configuration and add the hidden menu item to the list of menu assignments. Now you can load URL "./index.php?option=com_content&view=article&id=46&Itemid=53" and see the "Thank You" article with the "Example Pages" module.

Joomla now knows that when Itemid 53 is loaded, the "Example Pages" module should be added to the page. As mentioned, your hiddenMenu item's title is also the value that displays in the breadcrumbs. Note that since we did not actually add the hiddenMenu to the site's frontend, this entire effort remains transparent to your end users.

Hidden menus can be extremely useful in Joomla 1.5. They are worth having around for the purposes of module placement, and there are a number of useful components that support enhanced functionality if their content is added to a hidden menu. I hope this helps explain a little more about the intracacies of modules in Joomla 1.5 and offers useful work-arounds for fine tuning module placement.

Comments

Joomla 1.5: Display modules without assigning a menu item — 13 Comments

  1. Hi There,

    It’s really helpful article. this will solved my problem. you are really champ.. 🙂

  2. Thanks a million… finally found required solution after searching for almost a whole day

  3. thanks after 4 hours of searching, i stumbled upon this site…great help….thanks again  🙂