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?

template:

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

snippet:

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

<? echo $count ?>

<?php endif ?>

Like this:

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