Hello,
I’m trying to created a ‘Featured Projects’ page and have read many helpful threads on here about filterBy, filter and callbacks, but am still doing something wrong and would appreciate some pointers.
‘Featured’ is a ‘yes/no’ toggle in the blueprint for each ‘Project’ page in ‘Projects’.
I’m trying to get the first image or every visible page in Projects that has the Toggle as Yes:
<?php
$projects = page('projects')->children()->visible()->filter(function ($child) {return str::contains($child->featured() == 'yes') ? true });
foreach($projects as $project): ?>
<?php if ($image = $project->images()->sortBy('sort', 'asc')->first()): ?>
<img src="<?php echo $image->url() ?>" >
<?php endif ?>
<?php endforeach ?>`
Many attempts has led to many different errors. The current one is
Parse error: syntax error, unexpected '}'
So I think I’m just messing up the callback? Where am I going wrong?