i am trying to convert regular structures with title + (kirby)textarea fields to
structure with blocks - where as i am trying to convert the title to heading, and text to text… and it seems there’s some structures which work, and others who add the json into what’s being saved…
Before when i had pretty: true, it seem to have that while using the regular panel saving function as well, even though i have seen in earlier versions. by now pretty is disabled though.
$title = null;
$text = null;
$features = $page->features()->yaml();
foreach($features as &$feature){
$blocks = new Kirby\Cms\Blocks();
if(isset($feature['title']) && $feature['title'] != null){
$title = new Kirby\Cms\Block([
'content' => [
'text' => (string)markdown($feature['title']),
'level' => 'h2',
],
'type' => 'heading',
]);
$blocks = $blocks->add(new Kirby\Cms\Blocks([$title]));
}
if(isset($feature['text']) && $feature['text'] != null){
$text = new Kirby\Cms\Block([
'content' => [
'text' => (string)markdown($feature['text']),
],
'type' => 'text',
]);
$blocks = $blocks->add(new Kirby\Cms\Blocks([$text]));
}
if($blocks->count() == 0) continue;
$feature['blocks'] = Data::encode($blocks->toArray(),'json');
// tried many different variations of encoding (yaml, json, just plain toArray
}
$page->update([
'features' => Data::encode($features,'yaml'),
]);
There’s a few similar threads and infos, but all didn’t seem work…
Output e.g.
<div id="123">
[{"content":{"text":"[{\"content\":{\"text\":\"
Some Title here
\",\"level\":\"h2\"},\"id\":\"5350f449-f6d6-45eb-b4a8-1d75cdc36bbe\",\"isHidden\":false,\"type\":\"heading\"},{\"content\":{\"text\":\"
some text here here
.....
....
</div>
While others in the same loop may be fine.
In the Content File it seems as though it’s saving the whole thing wrongful in those cases.
blocks: '[{"content":{"text":"<p>[{\"content\":{\"text\":\...........
As it can be seen, it’s escaping and whatever.
The Structures come from version 3.9.x; and i am trying to convert it in a route using 4.1.2.
In the Structures, sometimes it’s saved with
field: >
longer text
or
field: |
longer text
or
field: ‘something’
By now i have also tested, if i create only a text structure and add the heading as a string (e.g. <h2>Bla</h2>
then the problem still happens. Is there another attempt to create blocks / update inside the structure and save the page?