Hi everyone,
I have recently developed a Kirby plugin that allows me to create dynamic blueprints. So far everything has gone smoothly, but I am now facing a problem for which I have not yet found a solution.
I have tried various approaches to solve my problem:
site/config.php:
...
'date' => [
'handler' => 'strftime'
],
...
Plugin index.php:
Kirby::plugin('username/package', [
'siteMethods' => [],
'blueprints' => [
'site' => function () {
return include __DIR__ . '/blueprints/site.php';
},
'pages/mitteilungen' => function () {
return include __DIR__ . '/blueprints/pages/mitteilungen.php';
},
'pages/mitteilung' => function () {
return include __DIR__ . '/blueprints/pages/mitteilung.php';
},
]
]);
blueprints/pages/mitteilungen.php:
$sections = [];
$groups = [];
if ($page = page('mitteilungen')) {
$callback = fn($p) => $p->created()->toDate('%Y');
// Gruppierung der Seiten nach Jahren
try {
$groups = $page->children()->group($callback);
} catch (\Kirby\Exception\Exception $e) {
$groups = [
'2002',
'2003'
];
}
// Iteration über die Gruppen und Erstellung von Abschnitten
foreach ($groups as $year => $itemsPerYear) {
$sections['section_' . $year] = [
'type' => 'pages',
'label' => 'Pages - ' . $year,
'query' => "page.children.filterBy('created', '^=', '".$year."')",
];
}
}
My goal is to create a section for pages for each available year.
Have any of you had similar experiences or any ideas on how to solve my problem? I would be very grateful for any help or suggestions!
Many thanks in advance!
Here you quote the $year variable, which does not make sense.
This is a typo of mine and it is not the problem. i have corrected my first post.
"page.children.filterBy('created', '^=', '".$year."')",
Could you describe what the problem is, please?
I do not receive a group ring in years. I would like to group the subpages in years and then output them in individual sections.
Baloralys:
created
Yes, I understand what you want to do, but I don’t see what you get instead. an error message? No sections at all…
Please post the complete blueprint for easy testing
Nothing at all, no error message nor any output
her my test fields:
'test' => [
'label' => 'Test',
'type' => 'fields',
'fields' => [
'test' => [
'label' => 'Test',
'type' => 'select',
'options' => $groups
]
]
]
Column (1/3)
No sections yet
Again, could you please post the entire PHP blueprint, not just bits and pieces. Assigning the groups to a field does not make sense, anyway, you need sections here.
<?php
$sections = [];
$groups = [];
if ($page = page('mitteilungen')) {
$callback = fn($p) => $p->created()->toDate('%Y');
// Gruppierung der Seiten nach Jahren
try {
$groups = $page->children()->listed();
} catch (\Kirby\Exception\Exception $e) {
$groups = [
'2002',
'2003'
];
}
// Iteration über die Gruppen und Erstellung von Abschnitten
foreach ($groups as $year => $itemsPerYear) {
$sections['section_' . $itemsPerYear->content()->created()->toDate('%Y')] = [
'type' => 'pages',
'label' => 'Pages - ' . $itemsPerYear->content()->created()->toDate('%Y'),
'query' => "page.children.filterBy('created', '^=', '".$itemsPerYear->content()->created()->toDate('%Y')."')",
];
}
}
$yaml = [
'title' => 'Bekanntgaben',
'icon' => 'megaphone',
'columns' => [
'main' => [
'width' => '2/3',
'sections' => [
'listed' => [
'label' => 'veröffentlicht',
'type' => 'pages',
'status' => 'listed',
'image' => false,
'layout' => 'table',
'query' => 'page.children.listed.filterBy("created", "^=", "20")',
'columns' => [
'created' => [
'label' => 'erstellt am:',
'display' => 'DD.MM.YYYY'
]
]
],
'grouped' => [
'label' => 'veröffentlicht',
'type' => 'pages',
'status' => 'drafts',
'image' => false,
'layout' => 'table',
'template' => 'mitteilung',
'columns' => [
'created' => [
'label' => 'erstellt am:',
'display' => 'DD.MM.YYYY'
]
]
],
'test' => [
'label' => 'Test',
'type' => 'fields',
'fields' => [
'test' => [
'label' => 'Test',
'type' => 'select',
'options' => $groups
]
]
]
]
],
'sidebar' => [
'width' => '1/3',
'sections' => $sections
]
]
];
return $yaml;
this is my last try since I created this post…
I’m out now and will look into this tonight.
Thank you and see you later
'test' => [
'label' => 'Test',
'type' => 'fields',
'fields' => [
'test' => [
'label' => 'Test',
'type' => 'select',
'options' => page('mitteilungen')->children()->listed()->toArray()
]
]
]
Call to a member function children() on null
wrong ID I used all the time. Sometimes I should take a break to find the error.