# Blocks in structures?

**URL:** <https://forum.getkirby.com/t/blocks-in-structures/22495>\
**Category:** Questions\
**Tags:** v3\
**Created:** [June 4, 2021, 7:37am UTC](https://forum.getkirby.com/t/blocks-in-structures/22495 "2021-06-04T07:37:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_herzog](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@m\_herzog](https://forum.getkirby.com/u/m_herzog)\
**Post date:** [June 4, 2021, 7:37am UTC](https://forum.getkirby.com/t/blocks-in-structures/22495/1 "2021-06-04T07:37:40Z")

</div>

I have a structure with a block inside. When i retrieve the structure with  
$statements = $page-\>references()-\>toStructure();  
and i whant to use the block inside with  
$statement-\>text()-\>toBlocks()  
I get the result shown in the attached image ?!?

What i am doing wrong?

 ![CleanShot 2021-06-04 at 09.35.32](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/b/b690b8ddac2463286f5ed08c9751c64ee4141edc.jpeg)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 4, 2021, 7:50am UTC](https://forum.getkirby.com/t/blocks-in-structures/22495/2 "2021-06-04T07:50:10Z")

</div>

I tested a simple example without issues in 3.5.5

Could you provide your structure field blueprint definition plus the complete template snippet?

---

<div class="post-metadata">

**Author:** ![m\_herzog](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@m\_herzog](https://forum.getkirby.com/u/m_herzog)\
**Post date:** [June 4, 2021, 8:08am UTC](https://forum.getkirby.com/t/blocks-in-structures/22495/3 "2021-06-04T08:08:23Z")

</div>

I am also using 3.5.5 an here are the code snippets:

1. I filter the active structure elements:

```auto
<?php
    $statements = $page->references()->toStructure();

    // filter active benefits
    $active_statements = array();
    foreach ($statements as $key => $statement) {
      if ($statement->active()->isTrue()) {
        $active_statements[] = $statement;
      }
    }
?>

```

1. After that i do HTML and a foreach loop:

```auto
<?php foreach ($statement->text()->toBlocks() as $block): ?>
<div id="<?= $block->id() ?>" class="block block-type-<?= $block->type() ?>">
<?= $block ?>
</div>
<?php endforeach ?>

```

1. yml for structure:

```auto
                fields:
                  image:
                    extends: sections/fields/attachments/motiv
                  title:
                    label:
                      de: Titel
                      en: Title
                    type: text
                  claim:
                    label:
                      de: Kernaussage
                      en: Claim
                    type: text
                  text:
                    extends: sections/fields/blocks
                  url:
                    label:
                      de: Verlinkung
                      en: Link
                    type: url
                  active:
                    label:
                      de: aktiv
                      en: active
                    type: toggle

```

the block field extends an existing definition:

```auto
type: blocks
pretty: true

fieldsets:
  text:
    label: Text
    type: group
    fieldsets:
      - heading
      - text
      - list
  media:
    label: Media
    type: group
    fieldsets:
      image:
        extends: blocks/image
        fields:
          image:
            image:
              back: white
            uploads:
              template: image-document        
      - video
  code:
    label: Code
    type: group
    fieldsets:
      - code
      - markdown

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 4, 2021, 8:28am UTC](https://forum.getkirby.com/t/blocks-in-structures/22495/4 "2021-06-04T08:28:26Z")

</div>

The issue is caused by setting `pretty: true`. So for the moment you can solve this by removing this setting. It’s probably a bug.

> <https://github.com/getkirby/kirby/issues/3395>
>
> \*\*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

---

<div class="post-metadata">

**Author:** ![m\_herzog](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@m\_herzog](https://forum.getkirby.com/u/m_herzog)\
**Post date:** [June 4, 2021, 9:23am UTC](https://forum.getkirby.com/t/blocks-in-structures/22495/5 "2021-06-04T09:23:44Z")

</div>

Ok, thanks for the fast reply and for opening the bug report!
