Extending multiple sections at once

Continuing the discussion from File changeTemplate not working:

I was adding multiple files sections to all of my templates using the section extend idea explained here Reusing & extending blueprints | Kirby CMS

And I was curious if I could extend multiple sections at once instead of altering all of the extends on all blueprints.
Here’s what I have been doing and it saves a lot of time but this code is in more than 30-40 blueprints:

sections:

  images:
    extends: sections/files.images
  pdfs:
    extends: sections/files.pdfs
  files:
    extends: sections/files.files

I know you can do this with fields blueprints by using the type: group as shown above in that link, but was curious if you could do the same with section blueprints. I don’t think you can.

When trying to force a file template for uploads into each section, do you have to declare the template used next to the extend like this:

sections:
  pdfs: 
    template: pdf
    extends: sections/files.pdfs

I ask because i’m trying to enforce the file blueprint in the extended section blueprint already but it doesn’t apply the template properly.

I’d assume that the problem is using the template prop before the extends prop.

I’ll give that a shot. Thanks, Sonja.

That helps, I think. I have them in so many places, but so far so good.

Related it’s interesting that when you extend a section blueprint for images, that you need to also include that it’s a type: files otherwise it breaks:

sections:
  images:
    extends: sections/files.images
    type: files

In general, I think I’ve found a way to avoid repeating myself in every section child blueprint by creating a child blueprint base that is extendable, as shown here:

As it says, one could override, hide parts based off what template it’s for (in the base file), and even add new fields and sections as needed.
That will help DRY up all of my blueprints and remove the need to extend a section or even several sections in all of the blueprints.

I’m curious that this is likely the way the old page ‘presets’ worked in blueprints, however the presets didn’t allow for modifications in the ‘extending’ of them like I’ve mentioned above. That’s a logical upgrade in my book. Love it.

I’ve stumbled on some curious behavior and am likely opening walls where I’m not supposed to.

For example, if I create a /blueprints/sections/files.yml blueprint that holds a group of files sections for pdfs, images, videos, and general files:

sections:
  images:
    type: files
    info: "{{ file.dimensions }} ({{ file.niceSize }})"
    image:
      cover: true
    size: small
    layout: cardlets
    help: "Curated display images only. Uses 'image' template."

So, for example, I could call them in a page blueprint like this:

sidebarSections:

  videos:
    extends: sections/files.videos
  pdfs:
    extends: sections/files.pdfs
  images:
    extends: sections/files.images
  files:
    extends: sections/files.files

It works, mostly, but even though in the section file i’ve declared what type of section ‘images’ is, it doesn’t work. I need to declare what type of section it is in the page blueprint that calls it. I know I mentioned this above.

It seems like I can not, however, define what template that section will use (for when I’m uploading files) in the page blueprint, but that it can’t be defined in the extended section file.

So:

files:
  extends: sections/files.images
  template: image

The template: image bit is supposed to restrict what template is applied to the file on upload. But if I define the template in the section file, it doesn’t work. You have to add it to the extends code like above.
This applies to several things, including help text, fetch, queries, etc. Essentially when you do this you end up not saving any time. It’s a notable difference between extending a fields file versus the sections files.

Best bet in this case is to go back to splitting up the section extends into separate files. That method works more reliably and as expected.

Conclusion

So, I wanted to document this but it seems super niche, edge case stuff.

I’m really not a dev so when I am exploring how to do these things I feel like i’m moving in a way that wasn’t developed for. But I’m learning nonetheless, and that’s good. I’m finding the walls, and feel like I can see better, actually.

Next

Again, next step is to actually convert everything over to the blueprint layout idea as shown in the Docs (linked above) and hope that the overrides I do for that saves me a ton of time and repitition.

I cannot reproduce that. Works fine for me, no matter where I define the template (section blueprint or the extended section in the page blueprint).

But wait, I tested that with Kirby 4, now let me test if it makes any difference in Kirby 5. In that case it would be a regression.

No, no difference in K5b6.

But what do you mean with group of sections.

A files section blueprint should look like this, without the sections keyword and without a name for the section:

type: files
info: "{{ file.dimensions }} ({{ file.niceSize }})"
image:
  cover: true
layout: cardlets
size: small
help: "Curated display images only. Uses 'image' template."
template: hello

There is no such thing a a section group similar to field groups.

The grouped fields blueprint is a brilliant feature. I just figured I’d try it out with sections to see how I could do it, to be more dry, for example.

You are correct, Sonja. Extending section blueprints works perfectly fine and defining templates, for example, works well in either place (page blueprint where extending or in section blueprint).

In my case I was extending sections from a file with multiple sections in it:

// site/blueprints/sections/files.yml

title: AllFiles

sections:
  images: 
    label: Images only
    type: files
    template: image
  files:
    type: files    

I was somewhat successful (using the dot notation as I’d shown above previously) at least partially. Just not entirely the way I’d hoped. Several of the modifiers like which template and more were just not working. So just to be clear I’m abandoning this idea.

I’m not very good at describing what I’m trying to do and how exactly I tested it, and what works and what doesn’t work, but I do feel like documenting what works and what doesn’t work beyond what’s in the Docs could be helpful to someone else. I’m mainly exploring and testing and learning.

I hope to have some success with the blueprint template idea and I’ll post my results here. Although, likely putting those successful explorations in a new post might be less confusing for everyone.

Thanks for you time. I appreciate it.

This approach with multiple sections in one file and trying to access it via dot notation in the page blueprint doesn’t work for me at all :thinking: Just getting invalid section type error.

Very strange.

In any event, this question is likely turning into a waste of time for everyone and I apologize.
I certainly don’t want to waste anyone’s time.
It’s probably best to delete it, as it may confuse learners that this is even a thing.

EDIT: I realize now that all of the signs throughout this entire experiment were not working, but I’d thought that it was. Seeing now that if i put ‘type: images’ in the ‘images:’ extend call, that it seemed to me to somewhat work, but that somehow the ‘files:’ extend was working means that in fact, it was not working at all.
Embarrassing.

Apologies, Sonja.