Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple files with labels #822

Open
fareesh opened this issue Apr 27, 2018 · 4 comments
Open

Multiple files with labels #822

fareesh opened this issue Apr 27, 2018 · 4 comments

Comments

@fareesh
Copy link

fareesh commented Apr 27, 2018

Is it possible to have multiple files on a page, each with its own label. The examples don't show an option of giving editors the ability to attach multiple files, each with their own label, or even alt text for that matter.

For example, if I am making a list of case studies. Some will have 3 reports, each titled, some will have 2 downloadable drawings, each titled.

Currently the only way to make it work seems like creating these as child pages. Is that the recommended approach?

@GBH
Copy link
Member

GBH commented Apr 29, 2018

Right now there's no easy way to do what you're describing.

Files are attached to Fragment model via has_many_attached :attachments. Out of the box ActiveStorage doesn't have any ways to add metadata to what you're uploading. I recall seeing a blog post that outlines how you can add that functionality, but I can't find it again. Even after you monkey-patch ActiveStorage::Attachment you'll need to have some sort of UI to add titles and alt-text for images handled by {{cms:files foo}} tag.

One way to solve your problem is to introduce a way to define collection of fragments. Here's what I'd imagine it would look like:

{{cms:collection images, render: false}}
  {{cms:file image}}
  {{cms:text title}}
  {{cms:text alt-text}} 
{{cms:end}}

Then you somehow pull images collection and using a view helper you can render html you want.

This feature is on the roadmap for version 2.1

For now you can always define tags like {{cms:file image_a}}, {{cms:text image_a_title}}, then b and c, etc. Clunky as hell but throw render: false on those and use a view helper to generate html based on fragments that are actually filled in.

@gr8bit
Copy link
Contributor

gr8bit commented Aug 11, 2019

Just a note on "metadata" for attachments: the current "best practice" approach is to introduce another custom attachment model for your app which has exactly one active storage attachment. Your model can then hold any metadata you require. We did that in two projects where we needed metadata (sort order and permission information) and it worked quite well. :)

@mbajur
Copy link

mbajur commented Feb 12, 2020

Hey @GBH - how is that thing with collections going? Has this been implemented in any way? As i can't find anything related to collections in the source code while this feature is sadly crucial for the project i need to start to work on :)

@GBH
Copy link
Member

GBH commented Feb 12, 2020

@mbajur unfortunately it's a non-trivial feature to add. If you have a requirement to support collections in some way, I suggest digging into Tag code and creating your own custom tag that can render form fields and save data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants