Blueprint groups

Support for blueprint snippets are great. To make it ā€œcompleteā€ it would be great to also have blueprint groups.

Example

Here are two blueprints. Both have the exact same setup of fields, except for the last one. All of them are actually snippets to make it easy to read.

The difference between them is the hero field in Template2.

title: Template1
fields:
  title: title
  subtitle: subtitle
  text: text
  image: image
  quote: quote
title: Template2
fields:
  title: title
  subtitle: subtitle
  text: text
  image: image
  quote: quote
  hero: hero

Maybe it donā€™t seems too bad, but having 30 fields in each and having 10 templates like this is much.

Solution - Blueprint groups

The group file

blueprints/groups/content.yaml exists and looks like this

title: title
subtitle: subtitle
text: text
image: image
quote: quote

The blueprints

Much shorter:

title: Template1
fields:
  my_group_key: content
title: Template2
fields:
  my_group_key: content
  hero: hero

Nested groups

If going far a group could contain other groups, nested groups. I donā€™t know how hard it would be to implement, but it can be good to know about the idea.

Also thoughts about something similar here:

2 Likes

It seems, there are already plans to have field groups in the future:

I have plans to add field groups with native tabs or some similar navigation concept to the next release. Thatā€™s why I havenā€™t added it here yet. (@bastianallgeier)

1 Like

I have a feeling that if you do that and also trying to extend groups, all that will introduce an unnecessary layer of complexity?

For me as site builder developer or for the Kirby core developer? For the site builder developer it would be too complex for small sites but for larger sites it can be a big help to structure things up.

I donā€™t have a great example of that right now but think of it as smaller groups with 2-5 fields that can be used in larger sets of groups. Larger groups for smaller group sets.

The benefit of it would be less code because of ā€œdonā€™t repeat yourselfā€ (DRY).

Iā€™m using a structure with limit 1 for now

Whats the best practice for this problem?

I want to extend a field-group multiple times.
I could think of a ā€œwrapper-fieldā€ which would then extend the group and the group-field-keys would have another scope like:

$page->field1->fieldgroupname();
$page->field2->fieldgroupname();

Best,
Sven

Your best bet are actually structure fields with only 1 entry unless you create a custom field, I think. Or use modules/subpages instead of a single page.

Hmmā€¦ because my field-group contains a structured field, this options is not applicable.
Is there a way i could build such a ā€œwrapper-fieldā€?

Blueprint:

fieldname:
   type: fieldholder
   extends: field-group
   #holds: field-group

anotherfieldname:
   type: fieldholder
   extends: field-group

Template:

$page->fieldname->fieldgroupfield();
$page->anotherfieldname->fieldgroupfield();

And then my field would somehow catch the fieldgroups and wrap it arround or is this limited due to the way kirby handles content files?

Without the Panel, writing and outputting such a nested structure is no problem:

Nestedfield:

-
    subfield1: >
      Text 1 (link: https://getkirby.com)
    subfield2: Text 2
    addresses:
      -
        sub1: Subtext 1
        sub2: Subtext 2
      -
        sub1: Subtext 3
        sub2: Subtext 4
- 
    subfield1: Text 3
    subfield2: Text 4
    addresses:
      -
        sub1: Subtext 5
        sub2: Subtext 6
      -
        sub1: Subtext 7
        sub2: Subtext 8

And get it out again in your template like this:

<?php

$struc = $page->nestedfield()->structure();
foreach($struc as $key => $value) {
  echo $value->subfield1()->kt();
  echo $value->subfield2()->kt();
  foreach($value->addresses() as $a) {
    echo $a->sub1() . ' | ' . $a->sub2();
  };
};

Maybe you can use the Engineer Field, havenā€™t tested it myself but it allows nested structures. Donā€™t know if this works with extending field groups.