Showing block field info as label

Hi all - I am using Kirby’s native blocks feature for the first time today and wondering how to show the content from a block as the label for said block. Please see below for an example of a simple FAQ page where each question and answer set is a block you can add. I’d like to show the question as the label for each block.

fields: faqs:
    label: FAQ's
    blocks:
    type: blocks
    fieldsets:
      faq:
        label: "{{ block.question }}"
        icon: question
        fields:
          question:
            type: writer
          answer:
            type: writer

Thanks!

You can just use {{ question }}. Since you are using a writer that will also return the html codes here though. You could possible create a fieldMethod to strip out the html tags with Html::decode($field) and then using {{ question.yourFieldMethod }} (haven’t tried that out though but I think it should work :upside_down_face:)

fields: faqs:
    label: FAQ's
    blocks:
    type: blocks
    fieldsets:
      faq:
        label: "{{ question }}"
        icon: question
        fields:
          question:
            type: writer
          answer:
            type: writer

Thanks a lot; hadn’t thought about the html! I prob should have said though, I’m looking to replace the actual block name (rendered as ‘k-block-name’; within the blocks the labels show as if they’re info and the block names are kinda the labels. In the example you’ve given the block still will always say ‘faq’ then the question next to that in the paler text that looks like info within a structured field (but rendered as ‘k-block-label’ in the DOM)

I don’t quite understand where you want this label to appear. Wouldn’t it make sense if you create a preview? So that it then looks like this:

Hi apologies for the late reply on this one, do appreciate the help.

Here is an example of a current faq block, where i’m using {{ question }} to show the label, which is great. But I wanted to know if I can remove, or customise each block’s ‘block name’ which is shown below as ‘Faq’ in bold. It seems you can only add the label after this, but it does mean if you have 30 entries, you have ‘faq’ repeating 30 times, which we already generally get as the block name is likely to be the same as the header above. Be cool to make this the question and then have something else after it if required.

As already mentioned above, you can create block previews that do exactly what you want them to do.