Use field blueprint multiple times

Hi,

I want to use a field blueprint multiple times on another blueprint (site’s blueprint).
It’s a simple field containing a url field and a select field (to store social links).

In my site.yml:

  - width: 1/3
    sections:
      social_links_company_1: fields/social-links
  - width: 1/3
    sections:
      social_links_company_2: fields/social-links
  - width: 1/3
    sections:
      social_links_company_3: fields/social-links

But I’m getting an error : The field name **"links"** already exists in your blueprint. which refers to my fields/social-links.yml blueprint.

type: fields        
label: Réseaux sociaux
fields:
  links:
    label: Liens
    type: structure
    fields:
      url:
        label: URL
        type: url
      type:
        label: Type
        type: select
        options:
          facebook: Facebook
          instagram: Instagram
          twitter: Twitter
          youtube: Youtube
          web: Web

Is it possible to reuse a custom field blueprint multiple times in the same screen?

Field names must indeed be unique in a blueprint, so you cannot reuse the same field names inside the same blueprint. But what you are actually doing here is repeat a fields section, if you would just reuse the single field it would work.

As far as I understand, I’m trying to structure data so it will produce this:

social_links_company_1.links.url,
social_links_company_1.links.type,
social_links_company_2.links.url,
social_links_company_2.links.type,
social_links_company_3.links.url,
social_links_company_3.links.type,

I understand links as a property of the social-links component. So, as a property it shouldn’t bother anyone if the property have the same name.

But what you’re telling me is that I can’t have 2 fields containing the same field name (with the same “property”)? or 2 field blueprints containing the same field name inside a page blueprint?

That really seems like an unconvenience to me, as I’m not able to use field blueprints like components.

How are we supposed to achieve that in K3?

Oh, I see, Kirby doesn’t actually care about the field’s (eg: social_links_company_1) name when it stores the data in the txt file.

How am I supposed to achieve something like that without copy/pasting my social-links field blueprint (which would be annoying, for the sake of DRY principle) everywhere?

I guess I could restructure my data so each link would contain a “company” field (select field).

Any other ideas?

For this particular use case:

In /site/blueprints/fields/social-links:

label: Liens
type: structure
fields:
  url:
    label: URL
    type: url
  type:
    label: Type
    type: select
    options:
      facebook: Facebook
      instagram: Instagram
      twitter: Twitter
      youtube: Youtube
      web: Web

In your site blueprint:

title: Test

fields:
  company1Social: fields/social
  company2social: fields/social
  #...