Global Field Definitions

If you have a lot of blueprints that often use the same fields, you will love Kirby's new global field definitions aka blueprint snippets. Once defined, global field definitions can be reused in all of your blueprints, and their instances can even be extended.

Defining a new field

Create a new fields folder inside /site/blueprints/. All your field definitions go into this folder.

Create a field definition, e.g. a date field and save as date.yml:

# /site/blueprints/fields/date.yml
label: Date
type: date
default: now

or an image select field:

# /site/blueprints/fields/imageselect.yml
label: Select an image
type: select
options: images

Using a field definition

Now you can reference your field definitions in your blueprints like so:

# /site/blueprints/mypage.yml
…
fields: 
  title: 
    label: Title
    type: text
  date: date
  myimage: imageselect
…  

This gives you full control over your field names.

Extending a field definition

You can easily extend a field definition if you want to overwrite the default behaviour, for example, give the field another label or set another default. Here is an example:

# /site/blueprints/mypage.yml
…
fields: 
  title: 
    label: Title
    type: text
  date: 
    extends: date
    label: Published
    default: false
  myimage: 
   extends: imageselect
   label: Cover Image

2.5.0 +

Field groups

It is also possible to define a set of fields as a field group and then import the whole group:

# /site/blueprints/fields/metadata.yml
type: group
fields:
  author:
    label: Created by
    type:  user
    width: 1/3
    readonly: true
  created:
    label: Created on
    type:  date
    width: 1/3
    readonly: true
    default:  now
  updated:
    label: Updated on
    type:  date
    width: 1/3
    readonly: true
    default:  now
    override: true
# /site/blueprints/mypage.yml
fields:
  title:
    label: Title
    type:  text
  metadata:
    extends: metadata

Of course you can extend and override any option of one of the group's fields:

# /site/blueprints/mypage.yml
fields:
  title:
    label: Title
    type:  text
  metadata:
    extends: metadata
    fields:
      author:
        label: Creator
      created:
        default: tomorrow
      updated:
        default: tomorrow