I got an one-pager from this tutorial:
https://getkirby.com/docs/cookbook/one-pager
On every section from this one-pager I loop through an invisible folder containing restaurant menu carts:
<?php foreach($pages->find('menu')->children()->visible() as $item): ?>
<div class="col-sm-12">
<button type="button" class="btn-card" data-toggle="modal" data-target="#modal-<?php echo str::slug($item->title()->lower()->html()) ?>"><?php echo $item->title()->html() ?>
<?php if($item->description()->isNotEmpty()): ?>
// <?php echo $item->description()->html() ?>
<?php endif ?>
</button>
</div>
<?php endforeach ?>
The loop from above renders all menu carts:
Question:
I need to show only certain menu carts on certain pages (the sections from the one-pager). Right now, I see all menu carts on all pages (the sections from the one-pager).
It would be cool, if I could use blueprint checkboxes (or another approach) in the panel to select the menu carts for each page.
That should be no problem, either use checkboxes or the multi-select custom field. I’m not quite sure how to help you? Selecting the pages to show as options?
fields:
selectMenu:
label: Select menu to show on page
type: checkboxes
options: query
query:
page: menu
fetch: children
text: '{{title}}'
value: '{{uri}}'
Ok your blueprint works just fine!
I think while you were happily typing away, I have edited my post above.
You blueprint code snippet works right out of the box
But what I use for the template file?
Not tested, but could work:
<?php
// create a new Pages object
$menuCollection = new Pages();
// fetch the value from the field into an array of URIs
$selectMenu = $page->selectMenu()->split(',');
// loop through the array and add each page to the new Pages object
foreach($selectMenu as $menuItem) {
$menuCollection->add($menuItem);
}
// loopy loop
foreach($menuCollection as $item): ?>
<div class="col-sm-12">
<button type="button" class="btn-card" data-toggle="modal" data-target="#modal-<?php echo str::slug($item->title()->lower()->html()) ?>"><?php echo $item->title()->html() ?>
<?php if($item->description()->isNotEmpty()): ?>
// <?php echo $item->description()->html() ?>
<?php endif ?>
</button>
</div>
<?php endforeach ?>
There’s a colon after my first foreach that shouldn’t be there… sorry. I corrected it above.
Thanks!
The code is working but there is no output, even when I select all checkboxes in panel.
Do I missing something?
Maybe it should read $data
instead of $page
in that line because of the one-pager. Do a dump to make sure you get the array you want.
dump($selectMenu);
I definitely should use more dump()