enter image description here

I created a custom utility template. Inside the template, I would like to use the built-in asset select modal for the "Add image" button. Any way to do this please?

1 Answer 1


The field is just a normal ElementSelect field with the element type craft\\elements\\Asset

{{ forms.elementSelectField({
    label: "Asset"|t('app'),
    id: 'assetSelect', 
    name: 'assetSelect',
    elementType: 'craft\\elements\\Asset',
   selectionLabel: "Choose"|t('app'),
   elements: elements, //array of selected elements 
 }) }}
  • @ Robin Schambach Sorry, I didn't make myself clear. When we select an image, there is a modal popping up, we can search in the search bar at the top and when we scroll down to the bottom, we'll get more images. I need the exactly same modal as this. Many thx!
    – yu xia
    Oct 31, 2018 at 21:19
  • Yeah and the script will add a button to open this modal Oct 31, 2018 at 21:20
  • Can I ask one more question please? Do you know how to limit the asset source? At the back-end, I get the volumeId and in the twig elementselectfield, I code like this sources: ['volumeId:'~volumeId]. But it's not working
    – yu xia
    Oct 31, 2018 at 22:27
  • Include the property criteria with the properties for your element query. criteria: {volumeId: 1, folderId: y} Oct 31, 2018 at 22:50

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.