0

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?

2
+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.

4
  • 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? 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
1

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;
        }
    }
?>

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.