Populate block's label field with a comma separated list of a structure field

Hi there!

I have a custom block type that contains a structure field, containing a name (text) field. Now I would like to list a comma separated list of the structure field’s names in the label of the block. I have no idea how to turn the structure field into a comma separated list. Are there any methods for that?

Thanks!

trych

Good question, I somehow doubt this is possible without a custom preview, because you would need the equivalent of this PHP code

implode(',', $block->structurefield()->pluck('name', ',');

So, it’s not possible then? Would it be reasonable to make a feature request for a Kirby implode method?

Well, you can create a preview instead of using the label.

In its most basic form it would look like this:

panel.plugin("cookbook/custom-blocks", {
  blocks: {
    blockname: `
        <div>
          {{ content.structurefield.map(item => item.name).join(', ') || 'No content yet' }}
        </div>
    `
  } 
});