Within my plugin, I have a need to open an Assets sheet and pick a file that has been uploaded and make use of it in my plugin. How is this possible? I am looking for something similar to the EE version of Assets that will allow me to programmatically use Assets with JS.

2 Answers 2


Something like this should get you going in the right direction:

Craft.createElementSelectorModal('Asset', {
    multiSelect: true,
    criteria: { locale: this.elementLocale, kind: 'image' }

See Brandon's answer here for more information and documentation: Is it possible to use the ElementType Modal UI for a custom Field Type Plugin?

  • Thanks for that answer. That looks like it's in the direction I want to go. I'll give that a shot and mark your answer correct if it works. Commented Aug 19, 2014 at 15:58
  • This worked out great. Thanks for the response. Commented Aug 20, 2014 at 2:59
  • Glad it worked out! I look forward to checking out the plugin when it's ready :-)
    – Peter Tell
    Commented Aug 20, 2014 at 3:01
  • I just released the plugin today and just updated it with a couple features (using the code in this post). Check it out. github.com/objectivehtml/Google-Maps-for-Craft Commented Aug 20, 2014 at 3:12
  • Wow, killer plugin Justin! Congrats on the release, it looks fantastic!
    – Peter Tell
    Commented Aug 20, 2014 at 13:17

I build a plugin called Lemmings that does this as one of it's built in functions.

Inside your plugin (depending on exactly what kind of plugin you're building) you'll need to include an element field aimed add accessing assets. Here's the one I used for Lemmings.

{{ forms.elementSelect({
     elements: t_element,
     id: 'thumbId',
     name: 'thumbId',
     elementType: t_elementType,
     criteria: {"kind":[],"localeEnabled":null,"locale":"en_us"},
     sourceElementId: thumbId,
     jsClass: 'Craft.AssetSelectInput',
     addButtonLabel: 'Select Thumbnail',
     limit: 1,
}) }}

Before you can build your html form/page. You'll need to register a control panel route (registerCpRoutes) and point over to an action. This action will rending your template and including the element type as defined below.

    $variables['t_elementType'] = craft()->elements->getElementType(ElementType::Asset);
  • This is useful information, but this doesn't help me. I specifically need to know how to access it programmatically with JS. With EE you can instantiate an Assets.Sheet object (or something like that) and it will have several methods to interact with Assets client side. Commented Aug 19, 2014 at 4:37
  • Sorry I guess I misunderstood your question. The above forms.elementSelect would allow you to utilize the built in asset selector/uploader just as if you were creating an entry. Anything outside of that and you'd have to create a custom modal/js/form etc. using some variant of craft()->elements->getElementType(ElementType::Asset) and output. Good luck! Commented Aug 19, 2014 at 14:46
  • I wrote all the JS in my plugin with Backbone.Marionette. It's very JS intensive and already have all tools in place to make this happen. I basically just need a button or anchor that drops down the assets sheet and allows users to select their file. Then once selected, the file url will be passed back to my plugin where that value is saved. I don't even need the upload feature, just the Assets file picker. Commented Aug 19, 2014 at 15:05

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.