Set template on upload to files section

Hi,

I have a files section, which I want to do the following:

  • Display files with templates of svg and image
  • When files are uploaded to it, apply a template of image

I can’t seem to get this to work. Below is the code I have:

sections:
  grid:
    label: Images
    type: files
    templates: 
      - image
      - svg
    layout: cards
    limit: 60
    uploads:
      template: image
    info: '{{ file.alt.or("⚠️ No alt text added") }}'
    text: "{{ file.filename }}"
    sortBy: filename asc

Should this be possible? Any help very appreciated.

Hi Mike

I guess it works when you define it like this:

uploads: image

All the best
Jakob

No that hasn’t worked - what I am trying to do might not be possible, but it seems like something that would be useful

Looking at the files section docs, I don’t think it’s possible. By setting the template option, you both restrict the list to files with that template and set this template on upload. Using multiple ones doesn’t seem to be supported as it’s of type “string”.

Thanks @thguenther - you are right. My use of an array in templates is actually having no effect, any file added is showing up regardless of template.

I will have a re-think and look at another approach.

Should be possible with a combination of the uploads prop and a query. Remove the templates prop, it doesn’t exist

According to the docs, the uploads property doesn’t exist :smiley:

My bad, the uploads prop only exists for the files field, not the files section.

Maybe a file.create:after hook could be an option to set the template, if the uploaded file is an image (unless there are other sections for uploading images in that blueprint)? And use the query prop to determine which files are displayed in the section. Although, I wonder where the files with template svg are coming from?

Thanks everyone for your thoughts.

For some context, my project setup has an images blueprint / page, which every other page uploads images to. I have found clients prefer this to the images being siloed to their individual pages. This is why there are a couple of different image types in there, as those are for specific content blocks used on the site.

Primarily users will be uploading from wherever they are making content edits, but I wanted to have a default image template just in case they uploaded direct to that images page for whatever reason.