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

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');
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

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?

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!