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?

3
  • 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
    Commented Aug 28, 2014 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
    Commented Sep 28, 2014 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
    Commented Oct 6, 2014 at 17:27

1 Answer 1

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.

3
  • 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
    Commented Oct 7, 2014 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. Commented Oct 7, 2014 at 18:24
  • Old link - but a dead one. Commented Mar 15 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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