Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am using Opencart 1.5.1 but have a theme made for 1.4.9.

The following template code won't work with 1.5.1:

<?php foreach ($modules as $module) { ?>
      <?php echo $module; ?>
<?php } ?>

Undefined variable: modules.
Invalid argument supplied for foreach().

What do I replace it with to work in 1.5.1? Thanks.

share|improve this question

2 Answers 2

up vote 2 down vote accepted
+50

Is modules defined? Do you know if you have modules set to show where that code is in the template?

You can do this:

<?php 
    if($modules){
        foreach ($modules as $module) {
          echo $module;
        }
    }
?>

This way if $modules is not set to anything, it ignores the foreach loop.

share|improve this answer
    
I receive "Notice: Undefined variable: modules in /.../common/home.tpl on line 20" –  Steve Sep 23 '11 at 11:16
    
Notices are not as serious as errors and can usually be turned off in the php config. Do you have any modules specified for the location this code is placed? –  Justin Pearce Sep 23 '11 at 14:00
    
No, I don't think so. I ended up rolling back from Opencart v1.5.1 to v1.4.9.6, which the template was compatible with. 2 hours later the author released a template compatible with 1.5. :-S Thanks for your help. –  Steve Sep 24 '11 at 13:12
    
Look at my initial reply with the "isset" below for the "Notice" problem :-) –  jflaflamme Sep 26 '11 at 22:12

Found a post about this question on opencart forums ..

Migrate theme from 1.4.9 to 1.5.1 (Undefined variable)s

Regarding the previous code, try the following :

<?php 
    if(isset($modules)){
        foreach ($modules as $module) {
          echo $module;
        }
    }
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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