$features = $page->features()->yaml(); //might as well use toSTructure here, but doesn't matter
$arr = [];
$i = 0; foreach ($features as $feature) {
$blocks = new Kirby\Cms\Blocks();
if (($feature['title'] ?? null) !== null) {
$title = new Kirby\Cms\Block([
'content' => [
'text' => (string)markdown($feature['title']),
'level' => 'h2',
],
'type' => 'heading',
]);
$blocks = $blocks->add($title);
}
if (($feature['text'] ?? null) !== null) {
$text = new Kirby\Cms\Block([
'content' => [
'text' => (string)markdown($feature['text']),
],
'type' => 'text',
]);
$blocks = $blocks->add($text);
}
if (($feature['cover'] ?? null) !== null) {
$arr[$i]['cover'] = $feature['cover'];
}
$arr[$i]['blocks'] = Data::encode($blocks->toArray(),'json');
$i++;
}
$page->update([
'features' => Data::encode($arr, 'yaml'),
]);
another attempt, still no success, my assumption is, that structures with blocks do not work flawless… Getting a text + textarea to update that info inside a structure > block shouldn’t be that hard.
It seems if there’s no structure, then I don’t run into that problem whatsoever.
As mentioned, there were similar problems before… like here:
Hello,
after two long nights without a solution I ask this.
I have a blocks field in a structure field. If I use a markdown- or textfield for a block, the saved json is broken/ invalid. I read about the “pretty: false” option and I switched it off.
Any ideas?
I use Kirby 3.8
THX
opened 08:36AM - 04 Jun 21 UTC
closed 09:20AM - 22 Sep 21 UTC
type: bug 🐛
**Describe the bug**
When using a blocks field inside a structure field and s… etting `pretty: true`, the output on the frontend is rendered as plain JSON. Works fine without this setting.
**To Reproduce**
See example here: https://forum.getkirby.com/t/blocks-in-structures/22495/4
**Expected behavior**
Should properly render blocks
**Screenshots**
**Kirby Version**
3.5.5
opened 01:05AM - 19 Oct 23 UTC
closed 08:23AM - 19 Oct 23 UTC
I have a structure field that includes blocks. If I add a code block, it doesn't… parse as HTML in my templates if the block includes multiple lines. My workaround has been to include one code block for each line, but this is not ideal.
Using latest Kirby (3.9.7)
This block setup:
<img width="1307" alt="Screen Shot 2023-10-18 at 9 02 36 PM" src="https://github.com/getkirby/kirby/assets/107688/cc109a88-e75e-4f51-a761-e1fe7a141d39">
and this template code:
```
<?php foreach ($page->reference_css()->toStructure() as $item): ?>
<div id="<?= $item->item()->html() ?>">
<h1><code><?= $item->item()->html() ?></code></h1>
<?= $item->info()->toBlocks() ?>
</div>
<?php endforeach ?>
```
Results in this
<img width="991" alt="Screen Shot 2023-10-18 at 9 03 25 PM" src="https://github.com/getkirby/kirby/assets/107688/bca116bc-0915-4960-a8fd-29ec29609b77">
opened 09:40PM - 20 Oct 21 UTC
closed 02:51PM - 03 Nov 21 UTC
**Describe the bug**
I am using blocks within a structure. All of the other t… ypes of block seem to be working fine but when i use the Markdown block it’s not rendering correctly.
This is how the .yml file is saving my markdown. It seems to be adding quotes around it
` documentation: '[{"content":{"text":"# An H1 Header\n## An H2 Header\n### An H3 Header\n#### An H4 Header"},"id":"d99269ab-21a5-4d21-94e7-7e9ff838238b","isHidden":false,"type":"markdown"}]' `
If i change it to this in the .yml file it works fine:
`documentation: |
[{"content":{"text":"# An H1 Header\n## An H2 Header\n### An H3 Header\n#### An H4 Header"},"id":"d99269ab-21a5-4d21-94e7-7e9ff838238b","isHidden":false,"type":"markdown"}]`
**To Reproduce**
Steps to reproduce the behavior:
1. In a .yml file create a 'structure' field
2. Nested within the structure field create a 'blocks' field
3. Go into the panel and add a structure and a markdown block within that
4. When you view the page in the browser the markdown isn't rendering correctly
**Expected behavior**
For markdown to be rendered correctly in the browser
**Screenshots**
How the panel looks with the markdown code:
<img width="836" alt="Screenshot 2021-10-20 at 20 41 30" src="https://user-images.githubusercontent.com/6408631/138175804-0a2bd1ca-f318-4ca7-9495-3ce9adb62380.png">
How it looks:
<img width="586" alt="Screenshot 2021-10-20 at 22 27 23" src="https://user-images.githubusercontent.com/6408631/138176141-6ef399b8-eeec-4f56-a531-be907eaacc18.png">
How it should look:
<img width="525" alt="Screenshot 2021-10-20 at 22 39 39" src="https://user-images.githubusercontent.com/6408631/138176220-fd3cd119-aed7-4612-81e4-32dea7e9f99f.png">
**Kirby Version**
3.5.7.1
**Console output**
No errors
**Desktop (please complete the following information):**
- OS: Mojave 10.14.6
- Browser: Firefox
- Version: 93.0