Functionality Needed: When user clicks on the item image it should filter and only show the following fields from that item (image, itemnumber, price and fulldescription).
What I’ve tried:
Controller (site/controllers/sidemenuproducts.php)
<?php
return function ($page) {
$filterBy = get('filter');
$unfiltered = $page->items()->toStructure();
$items = $unfiltered
->when($filterBy, function($filterBy) {
return $this->filterBy('item', $filterBy);
});
$filters = $unfiltered->pluck('item', null, true);
return [
'filterBy' => $filterBy,
'unfiltered' => $unfiltered,
'items' => $items,
'filters' => $filters
];
};
Template Section (site/templates/sidemenuproducts.php)
<table id="items_listing">
<tbody>
<?php foreach ($page->items()->toStructure() as $item): ?>
<tr>
<td>
<a href="?filter=<?= $item->itemnumber() ?>"><?= $item->image()->tofile() ?></a>
<br>
<?= $item->itemnumber() ?>
</td>
<td>
<?= $item->shortdescription() ?>
</td>
<td>
<?= $item->price() ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
^ I’m assuming it is not working because I need an If/Else statement in my template file, not sure what that code should be.
sidemenuproducts.yml
title: Sidemenu Page
tabs:
content:
icon: list-bullet
label: Items
columns:
main:
width: 1/1
sections:
fields:
type: fields
fields:
alert:
label: Alert
type: textarea
items:
label: Items
type: structure
fields:
image:
label: Image
type: files
max:1
imagedescription:
label: Image Description
type: text
itemnumber:
label: Item Number
type: text
newitemdate:
label: New Item Date
type: text
reducedprice:
label: Reduced Price
type: number
price:
label: Price
type: number
shortdescription:
label: Short Description
type: tinymce
fulldescription:
label: Full Description
type: tinymce
seotab: seo