InMotion Hosting Support Center

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:

position-3 position-6

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'));

testing-countmodulesIf 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).

Continued Education in Course 219: Joomla 2.5 Template Development Tutorial
You are viewing Section 3: Joomla 2.5 Templates - $this->countModules('position-3')
Section 2: Joomla 2.5 Templates - $showRightColumn
Section 4: Joomla 2.5 Templates - $this->params->get('templatecolor');

Joomla Community Google+ Hangout #3

June 3rd, 2014

Thank you @RustyJoomla for letting me speak on the Joomla Community Google+ Hangout!

Click here to watch!

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!