Blueprint groups


#1

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:


Tutorial: Global field definitions aka blueprint snippets
Reusing Multiple Fields
Snippet page type structure, with controllers
#2

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)


#3

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


#4

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).


#5

I’m using a structure with limit 1 for now


#6

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


#7

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.


#8

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?


#9

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.