How to set a variable for filterby from Panel

Hello again!

I got a specific question how to fetch specifical data from another subpage. I’ve got a page receipe.txt with following data

Title: Pizza Receipe
----
ReceipeID: 136-018-A
----
Date: 2018-09-21
----
Text: Get the best pizza

Now we go to another page where i want to add via Kirby Builder the Pizza receipe block. That page is receipe-overview.txt.

Now there I have following filterby component:

<?php foreach($site->index()->filterBy('receipeID, '*=', 'HOW TO CALL RECEIPE ID?') as $item): ?>
    <h2><?= $item->title()->html() ?></h2>
      <?= $item->text()->kirbytext() ?>
<?php endforeach ?>

I would like in panel to specify Receipe-ID, but I don’t know how to pass that value (called code_call to filter by part i noted above with “HOW TO CALL RECEIPE ID”. Anyone helping me would make me a very happy person :slight_smile:

Of course I thought something like this would work…

<?php foreach($site->index()->filterBy('receipeID', '*=', <?= $page->code_call()->html() ?>) as $item): ?>
    <h2><?= $item->title()->html() ?></h2>
      <?= $item->text()->kirbytext() ?>
<?php endforeach ?>

… what, of course, doesnt work :slight_smile:

Define your variable first:

<?php
$code = $page->code_call();
 foreach($site->index()->filterBy('receipeID', '*=', $code) as $item): ?>
    <h2><?= $item->title()->html() ?></h2>
      <?= $item->text()->kirbytext() ?>
<?php endforeach ?>

You could also use $page->code_call() (i.e. without the php tags and the html method ) directly, but the above solution is cleaner.

1 Like

This is great, thanks texnixe! Works like charm! I’m bloody beginner, but happy to work with a cms with great community :blush: