Page blueprint with conditional tab

@unmick, I’ve been playing around a bit trying to minimize duplication…

In a fresh Grav 1.7.7 installation, I created the following pages:

user/pages
├── ...
├── 03.blog
│   ├── blog-item
│   │   └── item.md            <-- standard blog-item
│   ├── blog.md                <-- standard blog page
│   └── gallery-item
│       └── gallery-item.md
└── 04.gallery
    └── gallery.md

And in Quark I defined the following blueprints:

user/themes/quark/blueprints
├── ...
├── gallery-item.yaml         <-- extends item    + adds gallery tab + imports gallery-bits
├── gallery.yaml              <-- extends default + adds gallery tab + imports gallery-bits
├── item.yaml                 <-- extends default + adds blog tab + imports blog-bits (already exists in Quark)
└── partials
    ├── blog-bits.yaml        <-- fields for item (already exists in Quark)
    └── gallery-bits.yaml     <-- fields for gallery
// gallery.yaml

extends@: default

form:
  fields:
    tabs:

      fields:
        gallery:
          type: tab
          title: Gallery
          import@:
            type: partials/gallery-bits
// gallery-item.yaml

extends@: item

form:
  fields:
    tabs:

      fields:
        gallery:
          type: tab
          title: Gallery
          import@:
            type: partials/gallery-bits
// partials/gallery-bits.yaml

form:
  fields:
    gallery_options:
      type: section
      title: Gallery Options
      underline: true

    header.gallery:
      type: text
      label: Gallery field

Notes:

  • The only duplicate code is the definition of a tab in gallery.yaml and gallery-item.yaml. I guess however, that that piece of code will hardly change over time. The changes will be in the partials/gallery-bits.
  • Mark the different extends@ blueprints gallery.yaml and gallery-item.yaml use.
  • Any changes in item.yaml and partials/blog-bits will automatically be available in the blog tab of gallery-item.yaml.
  • Any changes in the partials/gallery-bits.yaml will automatically be available in the gallery tab of gallery.yaml and gallery-item.yaml.

You wanted:

At each time i need a new parameter for the gallery, i add it in only one yaml.
At each time i need a new parameter for the blogitem, i add it in only one yaml.

I like to think I have achieved above requirements…