Joomla 2.5 Templates – $this->countModules(‘position-3’)

Joomla 2.5 has reached its end of life as for 12/31/2014. Please be advised this may be a security risk to your website. You can view more information about the end of life here.

Continuing with our tutorial on learning how to create Joomla 2.5 templates, we will once again review the following code:

// check modules
$showRightColumn        = ($this->countModules(‘position-3’) or $this->countModules(‘position-6’) or $this->countModules(‘position-8’));

In our last tutorial, we focused on what was the purpose of $showRightColumn. In this tutorial, we will again look at this section of code, but this time we will look at the countModules function.

Based upon the name itself, countModules, we can guess that this function will return the number of active modules in the given position. It is easy to test this theory, which we will do below.


How many active modules do we have in each position?

If you look at the code above, you will see that we are testing three different positions:

  • position-3
  • position-6
  • position-8

When we log into our Joomla Administrator section, we can go to Extensions » Module Manager to confirm how many modules we have in each position. Review the screenshots below:


As you can see in the screenshot, we currently have 2 modules active in position-3.


The above screenshot shows that we have 3 modules in position-6, but only 1 is active.

Because we didn’t have any modules in position-8, we didn’t have an option to filter modules by position-8.


What value does countModules return?

Now that we know how many modules are in each of these positions, we can test the countModules function to see what it actually returns. Here’s the code we are using to test the output of the function:

// check modules
$showRightColumn        = ($this->countModules(‘position-3’) or $this->countModules(‘position-6’) or $this->countModules(‘position-8’));
echo ”  <pre>
                this->countModules(‘position-3’) = ” . $this->countModules(‘position-3’) . “
                this->countModules(‘position-6’) = ” . $this->countModules(‘position-6’) . “
                this->countModules(‘position-8’) = ” . $this->countModules(‘position-8’) . “
“; die();

// check modules
$showRightColumn        = ($this-&gt;countModules(‘position-3’) or $this-&gt;countModules(‘position-6’) or $this-&gt;countModules(‘position-8’));


If you look to the right, you’ll see a screenshot of the results. As you can see, the return value of each countModules call returns the total number of modules active (which does not include disabled modules in that position).


It looks like this article doesn't have any comments yet - you can be the first. If you have any comments or questions, start the conversation!

Was this article helpful? Let us know!