I have 4 module positions, which based on the number of modules I'd like to resize the column width. I've written the following, but it's only setting them all to col-md-12. Any ideas where I'm going wrong?


        $bottom-col-width == "col-md-12";
    elseif($this->countModules('bottom-a') && $this->countModules('bottom-b'))
            $bottom-col-width == "col-md-6";
    elseif($this->countModules('bottom-a') && $this->countModules('bottom-b') && $this->countModules('bottom-c'))
            $bottom-col-width == "col-md-4";
    elseif($this->countModules('bottom-a') && $this->countModules('bottom-b') && $this->countModules('bottom-c') && $this->countModules('bottom-d'))
            $bottom-col-width == "col-md-3";
  • Read your code precisely. if bottom-a then width is col-md-12 elseif.... When module bottom-a exists, the elseif will not even be checked. Your first condition is true, so the if-clause ends here... so the next elseif's are ignored. – COBIZ webdevelopment Apr 1 '15 at 20:13

These if statements wont work. Imagine if there is module in positions bottom-b and bottom-c. Even if you would reverse if statements, none of those wont match.

To achieve what you want, if statements would be too complicated.

Rather do it like this:


// Default width - for one column
// This gets new value, if there is more than one active position
$bottomColWidth = "col-md-12";

// Number of positions, which have modules
$countOfActivePositions = 0;

// Positions to search modules in
$positions = array('bottom-a', 'bottom-b', 'bottom-c', 'bottom-d');

// Loop over every position
foreach ($positions as $position) {
  // If position has modules
    // Increase active positions count

if($countOfActivePositions > 1){
  $bottomColWidth = "col-md-".(12 / $countOfActivePositions);


This would work in every combination possible.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.