Kirby 3.5 blocks

I’m trying out the new kirby 3.5 blocks but I can’t get anything to render on the front end

can anyone advise where I’m going wrong with this?

site/templates/page.php

<?php foreach ($page->myBlocksField()->toBlocks() as $block): ?>
    <div id="<?= $block->id() ?>" class="block block-type-<?= $block->type() ?>">
    <?php snippet('blocks/' . $block->type(), [
        'block' => $block,
        'theme' => 'dark'
    ]) ?>
    </div>
<?php endforeach ?>

site/snippets/blocks/heading.php

<section class="heading">
    <?= $block->title() ?>
</section>

blueprint:

blocks:
        label: Page Builder
        type: blocks
        fieldsets:
          heading:
            name: Section header
            icon: bolt
            fields:
              title:
                type: textarea
                label: title

Wrong fieldname? The field in your blueprint is called blocks, in your template code you use myBlocksField().

What I find strange though, is that you are using a core block name without actually extending it.

1 Like

wow I’m an idiot…

How do you mean by using a core block name without extending it?

1 Like

heading is a default block name and I thought they needed to be extended to work, see this example: https://getkirby.com/docs/reference/panel/fields/blocks#extending-core-blocks

But if it works, then maybe it doesn’t matter and you can simple override it.

Ahh good to know thank you very much!

I was hoping you might be able to assist me with this:
I’m trying to create a global block type, I followed the documentation but can’t get it working, wondering if I am missing something obvious
In the panel block I get this error “Missing field setup”

site/blueprints/blocks/sectionhead.yml

name: section head
icon: bolt
fields:
  title:
    type: textarea
    label: title
  blurb:
    type: textarea
    label: blurb

site/blueprints/pages/about.yml

blocks:
  label: Page Builder
  type: blocks
  fieldsets:
    - sectionhead
    carousel:
      # fields

Strange, that should actually work (I copied your code as is into a Starterkit and it worked fine). Could you please post the complete blocks field definition you have in about.yml?

1 Like