I'm iterating through a folder using craft.assets, to select the folder I'll use the folderId.

What's the best way to find the folderId of a specific folder?

The only way I've found is to go the the Asset Settings page in the CP and hovering over a folder to see the url in the status bar in my browser.

Related Problem:

I created a folder in the CP Fields page (see image) and there seems no way to get this folderId as I cannot get to it in the Asset Settings page. As I only have a small number of folders I was able to figure it but it got me wondering if I was missing the obvious somewhere?



Folder added in Field page


You can find the id in the database in the craft_assetfolders table. Creating a field with uploads restricted to a single folder does not create an asset folder. The asset folder only gets created when you actually have an asset in that folder, so before that point there is no id.

  • Thanks for the answer Marion, it does seem there's no simple way within the CP without resorting to querying the db then. Not a problem though. – John Moylan Jul 19 '14 at 18:50

You can do it like that

// return an associative array with the asset source handle as key
$assetSources = craft()->assetSources->getPublicSources('handle');
$assetSource = $assetSources['yourAssetSrcHandle'];
$assetFolder = craft()->assets->getRootFolderBySourceId($assetSource->id);

I also find weird that there is no direct method to get this from an asset source handle...


Another approach is to inspect the sidebar element in the control panel using your browser. The screenshot below shows a media folder (id 9) that’s nested under a parent folder (id 1)

screenshot of the CP sidebar’s folder element


Checkout the blueprint plugin. It doesn't currently do this, but it does similar things.

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.