Is it somehow possible to use the same defined field more than once?

Hi, I noticed that 2.5.0 brought field groups for Global Field Definitions. I am able to extend a field and it’s working nicely, but it wasn’t clear how to use them more than once or if it’s even possible. For example:

# /site/blueprints/fields/section.yml
type: group
fields:
  section_headline:
    label: Section
    type: headline
  section_title:
    label: Title
    type: text
    width: 1/2
  section_image:
    label: Image
    type: image
    width: 1/2
  section_markup:
    label: Content
    type: markdown
  section_button_text:
    label: Button Text
    type: text
    width: 1/2
  section_button_url:
    label: Button URL
    type: url
    width: 1/2
  section_layout:
      label: Section Layout
      type: radio
      options:
        left: Image Left
        right: Image Right
        none: No Image
      default: 'none'
      width: 1/3
  section_animation_direction:
    label: Animation Direction
    type: radio
    options:
      left: Left
      right: Right
      none: None
     default: 'none'
     width: 1/3
  section_class:
    label: Section background
    type: radio
    options:
      section-def: White
      section-default: Gray
    default: section-def
    width: 1/3

and I want to use this in my blueprint like so:

title: Home

fields:
  title:
    label: Title
    type:  text

  section_1:
    extends: section
    fields:
      section_headline:
        label: Section 1

  section_2:
    extends: section
    fields:
      section_headline:
        label: Section 2

If this is not possible, please consider this as a suggestion. Thanks :slight_smile:

Peter

This does not work because you would end up with the same field names multiple times.

It’s the same as if you would create a blueprint like this:

fields:
  field_1:
    label: Field 1
    type: text
  # some more fields
  field_1:
    label: Field 2
    type: text
1 Like

This sounds like a great use for the Structure field! It allows you to group and repeat a set of sub-fields, all of which will have the same keys, names, behaviors, etc.

1 Like

Makes a lot more sense, yes. Because it wouldn’t make sense if Kirby somehow renamed those fields to make it work.

Or if you don’t like the structure field for such a purpose, use modules instead of having everything in one page.

Thanks guys. I was afraid that would be the issue.
@AugustMiller Thanks for the idea to use Structures.