I’m trying to create a table block like this:
$blocks = new Kirby\Cms\Blocks();
$blocks->add(new Kirby\Cms\Block([
'content' => [
'rows' => [
[
"dish"=> "Pizza",
"description" => "It's yummy!",
"price" => 12
]
]
],
'type' => 'table',
]));
site()->createChild([
'slug' => 'blocks-test',
'template' => 'blocks-test',
'content' => ['text' => $blocks]
])->publish();
where the blueprint is
fields:
text:
label: Inhalt
type: blocks
fieldsets:
- table
- text
But in the generated content txt file the text field is empty. It works for text blocks, just not for table blocks. I guess it’s because a block will be saved as html (at least toHtml()
is called on the Block) but a table block should be stored like a structure/array. Creating a table block manually in the panel stores the block in exactly the format I try to use:
{
"content": {
"rows": [
{
"dish": "Pizza",
"description": "It's yummy!",
"price": 12
}
]
},
"id": "...",
"isHidden": false,
"type": "table"
}