hello,
first i write into json file
$categoryData['exercises'][] = array(
'pdfs' => $randomExercise->documents()->filterBy("extension", "pdf")->pluck('url', ',',),
'vids' => $randomExercise->videos()->filterBy("extension", "mp4")->pluck('url', ',',),
…etc…
then i read the json file to output:
$categoryData = json_decode($jsonData, true);
then i put exercises of that $categoryData in a variable
$exercises = $categoryData['exercises'];
$exercises is a subarray in $categoryData.
then i loop through the exercises.
the following code works… but only when not in snippet:
<?php foreach ($exercises as $exercise) { ?>
<p><?= $exercise['title']['value'] ?></p>
<?php foreach ($exercise['vids'] as $videoUrl) : ?>
<div class="video">
<video controls><source src="<?= $videoUrl ?>" type="video/mp4"></video>
</div>
<?php endforeach; ?>
<?php foreach ($exercise['pdfs'] as $pdfUrl) : ?>
<div class="pdf">
<a href="<?= $pdfUrl ?>" target="_blank">[.pdf]
<?= getFilenameFromUrl($pdfUrl) ?></a>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
now i want to put the vids and pdf loops in a snippet, but then it stops working when i do:
snippet('vidsAndPdfs', 'exercise' => $exercise);
also tried
<?php snippet('vidsAndPdfs', ['videoUrls' => $exercise['vids']]) ?>
in the snippet
<?php print_r($videoUrls); ?>
returns nothing.
how can i pass the vids and pdf to the snippet? cant figure it out.
regards
fusi