Count + $data = array();

Trying to count each field called picture in my field form.
I think the easiet would be to create a count function in the foreach loop.
Is there a way to pull the count(); from the template into the snippet?


<?php $count=0; foreach($page->builder()->toStructure() as $section): { $count++; }?>
<?php snippet('sections/' . $section->_fieldset(), array('data' => $section)) ?>
<?php endforeach ?>


<?php if ($data->picture()->isNotEmpty()): ?>

<? echo $count ?>

<?php endif ?>

Like this:

<?php snippet('sections/' . $section->_fieldset(), array('data' => $section, 'count' => §count)) ?>
1 Like