Is it possible to add an if($count % 6 == 5):
statement inside the Json representation?
I’m looking for something like this:
<?php
$data = $pages->find('materials')->files();
$json = [];
$count = 0;
foreach($data as $file) {
$json[] = [
'name' => (string)$file->name(),
'type' => (string)$file->extension(),
if($count % 6 == 5):
'break' => 'true',
else:
'break' => 'false',
endif;
'url' => (string)$file->url(),
'texture' => (string)$file->material(),
];
}
echo json_encode($json);
Also I need to add the $count++;
somewhere to make it count up. I already feel like I’m completly wrong.
I must admit that I copy pasted this from the php template in which I made the same thing work like this:
<?php
$images = page('materialen')->files()->shuffle();
$count = 0; ?>
<?php foreach($images as $image): ?>
<?php if($count % 6 == 0): ?>
<ul class="container">
<?php endif ?>
<li>content…</li>
<?php if($count % 6 == 5): ?>
</ul>
<ul class="panel"></ul>
<?php endif ?>
<?php $count++; endforeach ?>