3

I'm building a customer portal for work, and we are storing customer-facing files on the site in an Amazon S3 bucket. I currently have it all set up as a Structure section with an Asset field. I query for each entry using its uri, and for Folder Entry Types I pull and output its children.

My hope is that I can instead query for Asset folders and files directly, and then add a few fields to Assets (through the usual methods). Querying for files is fine, but I can't see any variables to pull folders. Would I need to write a plugin for this?

  • There's no function for this (yet?), but you could try fetching them over craft.assets and asset.getFolder and build your custom asset folder object with Twig :D – carlcs Aug 28 '14 at 14:49
  • Went to answer this, @carlcs, but realized I was going to type exactly what was in your comment. Want to add it as an answer? – Brad Bell Sep 28 '14 at 22:49
  • @Brad I'm not sure this is a working solution, that's why I wrote "try". Yes, this is rather easy if you don't nest folders. But if you do, you need to reconstruct the assets' complete folder structure with asset.getFolder, parent and id. – carlcs Oct 6 '14 at 17:27
3

Writing a plugin would be your best shot. You can use AssetsService to get all the information you need (http://buildwithcraft.com/classreference/services/AssetsService)

This might change with a future release, but the need to query Assets folders directly from a template is so rare, that I'm not entirely convinced it will make it's way into a future release at this point.

| improve this answer | |
  • Thanks Andris for giving a proper answer. I probably disagree with you that there's only rare use cases for this. Uploading assets on a batch to create entries could be a convenient way to add content. Think photographers etc.! Would it be possible to also read metadata from the files and write those into asset fields. This would allow to edit your project (portfolio etc.) in an external app like adobe lightroom. :) – carlcs Oct 7 '14 at 11:19
  • Yeah, calling it "so rare" was probably an overkill. I'm still leaning towards the plugin route, though, since the methods are all there in the service and AssetFolderModels already have methods for traversing the tree. As for the metadata - it's on the list, but that will most likely require Imagick installed. – Andris Sevcenko Oct 7 '14 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.