Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted

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

You can do this:

        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 :

        foreach ($modules as $module) {
          echo $module;
share|improve this answer

Your Answer


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.