trilbymedia / grav-plugin-flex-objects

Powerful and supremely flexible object support for Grav
MIT License
38 stars 10 forks source link

File upload and presentation with json storage #136

Open PeterB513 opened 2 years ago

PeterB513 commented 2 years ago

I read in the description that it is only possible to present an uploaded file in flex as it is stored as folder storage. I made a flex object solution with json storage. It includes an uploaded a file in de json file. The file represents a bookcover of a stored book.
What I noticed is that the uploaded file data is stored in the json file. The actual file is stored in de same folder as the json file. I also noticed that the uploaded file in this solution is presented in the admin of this flex object.

With this solution, I tried to present the collection via twig. All the text fields are presented but not the image. My question is, even if description says that it not possible, is there a way to present the image via twig? Because in admin the image is presented correcly and all the ingredients are in the json file. If there is a way, what is the twig code solution? Or should I use folder storage anyway.

mahagr commented 2 years ago

Use object.media[...] or even object.getMediaField('fieldname')[...], both should work. With the second approach, you can even loop through the images.

That said, I'm currently working on making it even easier to work with the relationships, but that code hasn't been committed yet.