Actions

Counting modules in multiple module positions

From Joomla! Documentation

Revision as of 07:33, 18 July 2014 by Dgt41 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Basic usage of the countModules method is explained here

The countModules method can be used to determine the number of Modules in one given Module position.

The argument to the countModules function is normally just the name of a single Module position. The function will return the number of Modules currently enabled for that Module position.

Since Joomla! 3.0 all the official templates use plain php code in order to calculate the number of multiple modules positions. This code calculates the content width, and is found in index.php of protostar:

// Adjusting content width
if ($this->countModules('position-7') && $this->countModules('position-8'))
{
        $span = "span6";
}
elseif ($this->countModules('position-7') && !$this->countModules('position-8'))
{
        $span = "span9";
}
elseif (!$this->countModules('position-7') && $this->countModules('position-8'))
{
        $span = "span9";
}
else
{
        $span = "span12";
}

This code is used in the main area of the template and automatically arranges the width of it. So if user enabled some modules in the left side, the widths will become span9 and span3 respectively (span12 is full width). If user enables both left and right, the widths will become span3 span6 span3. And if no modules are enabled, either left or right, the width will become span12 (full row).