Page Identification

(7 votes, average 4.29 out of 5)

“How do I get MetaMod to detect when I am on a certain Joomla page?”

... this is one of the most frequently asked questions about MetaMod.

MetaMod 2.0 introduces a new debug mode called Advanced, to help you to design rules that target just about any page on your site.

With Advanced Debug mode turned on in MetaMod, and the MetaMod set to display on ALL pages, navigate to any page on the front end of your site. You will see a new block of information in your MetaMod, as shown.

PHP code is automatically generated. The code in the block can help you to identify an exact page on your site, as it creates a rule that utilises any $_GET and $_POST variables that were sent from the browser and/or added by Joomla after the request was received.

Using the Page Identification Information

  1. Turn on Advanced debugging in MetaMod
  2. Set your MetaMod to display on ALL pages (using the Menu Assignment box)
  3. Navigate to the page that you want to identify (you may want modules to appear on that particular page, or perhaps want them to not appear on that page).
  4. Copy and paste the information from the Page Identification box into the PHP box in your MetaMod.
  5. Replace XXX with the module ID or module position name that you want to appear on that page.

If you want modules to appear on every page except the one you have just identified, do the following:

  1. Follow the steps above, replacing XXX with the module ids or module position names that you want to exclude
  2. Change the first line from “if (” to “if ( ! (”
  3. Add an extra “)” at the beginning of the line with the “return” in it.

Here’s a finished example. In this example, module 123 will be displayed on all pages except the WebLinks “categories” page:

if ( ! (
$option == 'com_weblinks'
and $view == 'categories'
and $Itemid == '155'
) ) return 123;

There are many more ways you might want to manipulate this — for example you might wish to display one module on the WebLinks categories page but a different one on the individual category pages. By viewing the Page Identification information when on a category page, we see the following structure:

if ( 
 $option == 'com_weblinks'
 and $view == 'category'
 and $id == '2:om-websites'
 and $Itemid == '155'
) return XXX;

From that we can see that $view changes to “category” when we’re on that page.

Our finished rule for including a module on the WebLinks “Categories” page, but a different one on the individual “category” pages would be as follows:

if (
$option == 'com_weblinks'
and $view == 'categories'
) return 101;
else if (
$option == 'com_weblinks'
and $view == 'category'
) return 102;

Optional Parameters


Due to the complexity of Joomla’s request system, the rules shown may contain extra variables or information that are unnecessary or incorrect, but MetaMod does its best to identify and warn you of these.

For example, $Itemid identifies the exact menu item that was clicked on to get to the page you are on. You may want to leave this out, so that the rule will be triggered no matter which menu item was clicked on.

Also, the frontpage component sometimes adds a parameter called “limit” which identifies the maximum total number of items to be displayed on the frontpage. There’s no need to include this in the rule, as the front page can be detected using the “option”, “view”, and optionally “Itemid” alone (although you don’t even need the Itemid, just the option and view).

For the frontpage shown on the right, you could simply use this rule:

if ($option == 'com_content' and $view == 'frontpage') return 101;

When MetaMod can identify which parameters may be optional, it displays /*!*/ at the end of a line, as shown:

if ( 
$option == 'com_content'
and $view == 'frontpage'
and $Itemid == '1'
and JRequest::getVar('limit') == '9' /*!*/
) return XXX; /* replace XXX with the module ID or position to display */

The detection isn’t perfect, particular if the page was reached as a result of a POST request (e.g. from a form). However for many other types of pages it is quite accurate, and you should feel free to remove those lines after pasting the rule into the PHP box in MetaMod. Experiment.

Last Updated on Monday, 12 October 2009 04:21