Hi everybody,
I try to create a plugin with a dynamic blueprint and now I have two questions.
how can i debug my plugin-blueprint? if i call a var_dump the page breaks with an error.
how can i get the current page in the blueprint? if i use page() it is aways the root, but I need the current page.
thanks in advance
bnomei
July 23, 2020, 8:57am
2
hi @gegerino . welcome to the forum.
what exactly do you mean with “dynamic blueprint”? a blueprint file and template file registered via plugin?
can you share some of your code for questions 1 and 2?
Here is my code:
<?php
Kirby::plugin(‘digtive/productanswers’, [
‘blueprints’ => [
‘pages/product’ => require_once DIR . ‘/blueprints/pages/product.php’
],
]);
product.php -> blueprint-file:
<?php
$blueprint = [
‘title’ => ‘Product’,
‘status’ => [
‘draft’ => ‘Draft’,
‘listed’ => ‘Published’
],
‘options’ => [
‘preview’ => false,
],
‘columns’ => [
‘main’ => [
‘width’ => ‘1/2’,
‘sections’ => [
‘content’ => [
‘type’ => ‘fields’,
‘fields’ => [
‘headline’ => [
‘label’ => ‘Überschrift’,
‘type’ => ‘text’
]
]
]
]
],
‘left_side’ => [
‘width’ => ‘1/2’,
‘sections’ => [
‘side’ => [
‘type’ => ‘fields’,
‘fields’ => []
]
]
]
]
];
$questions = page('gnss')->find('questions')->children()->published();
//this crashes var_dump($questions);
foreach($questions as $question):
$questions_array[ $question->title()->value() ] = [
'label' => $question->title()->value(),
'type' => 'multiselect'
];
endforeach;
$blueprint['columns']['left_side']['sections']['side']['fields'] = $questions_array;
return $blueprint;
sorry for this ugly formation
bnomei
July 23, 2020, 9:07am
5
the page
helper will not work since all your code is loaded as part of the config and kirby is not ready yet. you could try and defer some of your plugins logic to the ready option . but i am not sure this will work with the blueprint you have in mind.
bnomei
July 23, 2020, 9:10am
6
but instead of page
you could walk the dir tree and create virtual page objects based on your content file using Page::factory
.
okay… thx
and is it possible to do a var_dump or something in my blueprint?
bnomei
July 23, 2020, 9:14am
8
since its part of kirbys init i do not think so. but you could dump it to a file.
$msg = print_r($var, true); // if you need a var not just a string
@file_put_contents($file, $msg, FILE_APPEND);