Open hdodov opened 5 years ago
I often times find myself prefixing a lot of fields that are logically grouped. I usually divide the site in sections and each section has its own prefix so I can differentiate between sectionOne's title and sectionTwo's title. Perhaps we can have a syntactic sugar for prefixing with the use of a dollar sign:
fields:
heading:
type: text
$footer:
title:
type: text
content:
type: textarea
links:
type: structure
fields:
link:
type: url
text:
type: textarea
Which could be the same as:
fields:
heading:
type: text
footer:
type: group
prefix: true
fields:
title:
type: text
content:
type: textarea
links:
type: structure
fields:
link:
type: url
text:
type: textarea
Which functions like:
fields:
heading:
type: text
footerTitle:
type: text
footerContent:
type: textarea
footerLinks:
type: structure
fields:
link:
type: url
text:
type: textarea
I like the first idea a lot as it is quite intuitive, fully backwards-compatible and also rather simple to integrate into the current code structure. I'm not so sure about the other idea though – it seems quite complex and would be hard to document and understand.
@lukasbestle I also had the same concerns, but Kirby encourages a certain style of field naming, while using symbols such as $
is even advised against. Therefore, the people using this would know what they're doing.
I think that saying:
$footer:
title:
is the same as:
footer:
type: group
prefix: true
fields:
title:
...would be enough for people to understand the feature clearly - it's just a shorthand. You can define fields
in a blueprint without necessarily having to add tabs
, columns
, and sections
before that. This functions in a similar fashion except it utilizes the field name so Kirby can make a difference between field groups and actual fields.
Edit: This even holds true for nested groups. The following:
footer:
type: group
prefix: true
fields:
test:
type: text
title:
type: group
prefix: true
fields:
bar:
type: group
prefix: true
fields:
baz:
type: text
...works in Kirby 3.2.3 and correctly outputs two fields in the panel. With prefixing, it would look like:
$footer:
test:
type: text
$title:
$bar:
baz:
type: text
It would open a whole new dimension in field organization for blueprints. Add to this the fact that you can extend those groups - and you get a lot of useful stuff, in my opinion.
To be honest I disagree – every shorthand we add increases system complexity.
I have a field group groups/section.yml:
And a page that includes it:
That works great, but what if I need another section with exactly the same fields? I can't simply include the section again because it would add the same fields. Should I copy the section and maintain two almost identical files? No, but I've got no choice.
My proposal is to have a
prefix
option when using groups that automatically prepends a string to all fields' names. Since Kirby works in a case-insensitive manner, that shouldn't be a problem?This is what I imagine:
groups/section.yml:
page:
Which would be the equivalent of adding
sectionOneTitle
,sectionOneContent
,sectionTwoTitle
, andsectionTwoContent
. This way, I can use a field group unlimited number of times and in any context.