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
position-3

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

position-6

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') . "
        </pre>
"; 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).

Like this Article?

Login to comment.

Your Opinion Matters

... but we need to know what you're thinking!

I'm Brad Markle, your friendly Community Support technician, and I wrote the article you're looking at now. I like to think it's perfect, but I'm sure you have some suggestions. Please, let me know what they are!

Feedback
Your Email Address
Because we'd like to talk with you!

Latest Questions

If you need some help, submit your question to our Community!
We guarantee a response within 60 minutes (8am - 9pm EST, Monday - Friday)
Ask a Question!
Recent Questions
  1. Domain not pointing to my inmotion hosting
  2. How do I transfer my domain from inmotion to a different domain service?
  3. How many ways can you annoy your customers?

Need more Help?

Search

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: support@InMotionHosting.com
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!