1

I have this code here:

<div class="<?php echo $this->class; ?> block <?php echo $this->field('style')->value(); ?> <?php echo $this->field('columns')->value(); ?> <?php echo $this->field('margin_top')->value(); ?> <?php echo $this->field('margin_bottom')->value(); ?><?php if($this->field('margin_top_mobile')->value()): ?> <?php echo $this->field('margin_top_mobile')->value(); ?><?php endif; ?><?php if($this->field('margin_bottom_mobile')->value()): ?> <?php echo $this->field('margin_bottom_mobile')->value(); ?><?php endif; ?>"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
    <div class="ce_featurelist_inside">
        <ul>
        <?php foreach($this->group('list') as $i => $fields): ?>
            <li class="item item_<?php echo $i; ?>">
                <?php if($this->field('link#'.$i)->value()): ?>
                <a href="<?php echo $this->field('link#'.$i)->value(); ?>" title="<?php echo $this->field('link#'.$i)->option('titleText'); ?>"<?php if($this->field('link#'.$i)->option('target')): ?> target="_blank"<?php endif; ?><?php if($this->field('link#'.$i)->option('lightbox')): ?><?php echo $this->field('link#'.$i)->option('lightbox'); ?><?php endif; ?>>
                <?php endif; ?>
                
                <?php if($this->field('font_icon#'.$i)->value()): ?><i class="icon <?php echo $this->field('font_icon#'.$i)->value(); ?>"></i><?php endif; ?>
                
                <?php if($this->field('image_icon#'.$i)->value()): ?><div class="icon"><?php echo $this->field('image_icon#'.$i)->html(); ?></div><?php endif; ?>
                
                <span><?php echo $this->field('item#'.$i)->value(); ?></span>
                
                <?php if($this->field('link#'.$i)->value()): ?>
                </a>
                <?php endif; ?>
                
            </li>
        
        <?php endforeach; ?>
        </ul>
    </div>
</div>

The problem is that I have this error : "Warning: Invalid argument supplied for foreach()" I have:

  • PHP version 7.3.27
  • Contao Manager 1.4.2
  • Contao 4.7.6 (API version 2)

When I run the dubug mode on test.com/app_dev.php It shows me that error :

"ErrorException: Warning: Invalid argument supplied for foreach() at templates/layout/customelement_featurelist.html5:4 "

The website works properly but I can't update anything.

Is there any idea of what happening?

  • 1
    Does this answer your question? [Invalid argument supplied for foreach()](https://stackoverflow.com/questions/2630013/invalid-argument-supplied-for-foreach) – urfusion Apr 13 '21 at 07:12
  • No @urfusion. I use CMS and this is a code inside of the template. I have not so much knowledge but I know that the website is working properly – Nick Zagkanas Apr 13 '21 at 07:15
  • Dump `$this->group('list')` and see what you're getting. – El_Vanja Apr 13 '21 at 08:27

1 Answers1

0

Generally the Contao extension which uses the template "templates/layout/customelement_featurelist.html5" should ensure, that the array of "$this->group('list')" is not empty or null. So, check the configuration to be sure there is nothing missing.

If the error still exists follow the link of @urfusion and use the instruction of the 2. entry.

Edit the file "templates/layout/customelement_featurelist.html5" and insert the array checking before line 4 (closing after line 22).

If you need support you can also go to thze official Contao forum and askyoure questions (even in german).