i am a php newbie and only need php to understand kirby a little bit.
I want to filter and display elements depending on a page without going to another url.
In fact i want to recreate parts of the cookbook.
my idea:
simply changing the filter on buttonclick and display different results.
but how can i change the filter via clicking an url?
I looked up some party of the cookbook to get the idea but dont understand all of it.
can someone explain this to me?
I know how to foreach works, but:
where are the $categories defined?
what is e()
its not one single recipe. It is the code from the cookbook.
I cloned getkirby.com from github -> and looked up the cookbook.php and the relating components
<button> get everything from Category1</button>
<button> get everything from Category2</button>
<?php
foreach (page()->children()->filterBy('tag', $changingFilterOnButtonClick) as $subpage) : ?>
<?= $subpage->title() ?>
<?php endforeach ?>
So depending on wich button i click i want to change the filter.
how to i get the parameter from a button?
It would be ok if i have to do it hardcoded
You don’t. A button doesn’t change your url, you either need a link here like on the getkirby website or you have to change the url via JS if you use a button.
Because the cookbook content is divided into subfolders as categories (instead of assigning the categories to a subpage via a field). So this is a redirect, because the subfolders should not be accessible.
So if the category is nature, and a subpage has ONLY the tag nature, it will be shown.
If the category is nature and a subpage hast the tag nature AND the tag sport, it wont be shown…
So i just finished creating the blueprints and designing the site.
I added a breadcrumb with “help” as start.
Now i want to add a href to the help, with gets back to the category choosen on the page before.
To make it simple, the first tag of the page iam on should define the category.
This code returns an array with all tags. Trying to echo an array will result in an error, because an array is something you have to loop through or implode before you can echo it.
To get only the first part of your array, you can access the first element by its index:
$firstTag = page()->tags()->split(',')[0];
But because we can never be sure that our array is not empty and that the index actually exists, we better do it like this:
<?= page()->tags()->split(',')[0] ?? null ?>
If the index exists, the first element will be printed, otherwise nothing.