Can I extend the fields of a custom block I created?

I have created a custom block, containing 2 fields (text and pages).

I’ld like to be able to filter the pages field in that custom block via the blueprint of the template I’ve added the blocks field in. But that extend doesn’t seem to do anything?

FYI, I have also tested a simpler extend: use another label for the text-field.

Also doesn’t work.

Could you please post what you tried?

Sure,

This is the blueprint of my custom pagelist block:

name: Pagelist
icon: page
tabs:
  main:
    label: Main
    fields:
      text:
        type: text
        label: Text
        placeholder: Text
        required: true
      pagelist:
        type: pages
        label: Pages
        required: true

And this is part of the blueprint I used in a template for the blocks field:

type: blocks
pretty: true
fieldsets:
  linked_content:
    label: Linked content
    type: group
    fieldsets:
      pagelist:
        extends: blocks/pagelist
        fields:
          text:
            label: Test

I would’ve expected the label of the text field in a pagelist-block to be Test instead of Text, but that’s not the case.

It should actually work, I tested this example:

          newblock:
            extends: blocks/newblock
            name: xTendedBlock
            fields:
              text:
                label: lala
              files:
                query: page.images

@texnixe , I can’t get this to work …

Do you have something special in your newblock?

I just did this quickly, this is newblock.yml

name: Newblock
icon: tag
preview: text
wysywig: false
fields:
  text:
    type: text
  files:
    type: files
    query: site.images

This is the field in note.yml

columns:
  - width: 2/3
    # This columns only has a single field
    fields:
      blocks:
        type: blocks
        fieldsets:
          linked_content:
            label: Linked content
            type: group
            fieldsets:
              newblock:
                extends: blocks/newblock
                fields:
                  text:
                    label: Lala

@texnixe , did you store newblock.yml in a plugin? Or in site/blueprints/blocks?

I just tried putting your code in site/blueprints/blocks/newblock.yml, and then it works.
Pasting exactly the same code in sites/plugins/kirby-block-pagelist/blueprints/blocks/pagelist.yml and adding it to the sites/plugins/kirby-block-pagelist/index.php as blueprint doesn’t work:

Kirby::plugin('bvdputte/pagelist-block', [
  'blueprints' => [
    'blocks/pagelist' => __DIR__ . '/blueprints/blocks/pagelist.yml'
  ],
  'snippets' => [
    'blocks/pagelist' => __DIR__ . '/snippets/blocks/pagelist.php',
  ],
]);

AFAIK, adding the blueprint for the block inside the custom block plugin is the way to go, right?

Yes, no plugin tested. Will verify tonight.

1 Like

I checked your example, and yes, as is, it doesn’t work. But the problem is not that it’s registered in a plugin, but that you are using tabs within your custom block. And to extend the tabs, you need to change the syntax, which might get a bit tricky. I.e. extend the tab and then the fields within.

In that case, it might sense to put the tabs into separate files and extend those.

Thanks for pointing figuring out my mistake, Sonja!

When extending the tab, it works as expected indeed!