I want to have a downloadable link in my admin form. I want to fetch file name from my table and file is located under Magento_Root/pub/media/ directory. Note: this form is being used for just edit few fields (mainly informative)


You need to create your own field to add download link in Ui form

Add new field in ui form with elementTmpl

<item name="elementTmpl" xsi:type="string">Vendor_Module/form/element/download</item>


<field name="download">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="template" xsi:type="string">ui/form/field</item>
            <item name="elementTmpl" xsi:type="string">Vendor_Module/form/element/download</item>
            <item name="label" xsi:type="string">Download Here</item>
            <item name="dataType" xsi:type="string">text</item>
            <item name="formElement" xsi:type="string">input</item>
            <item name="source" xsi:type="string">sampleform</item>

Now create download.html at


Add your custom html like add <a href="download_link"></a> in download.html

  • how can we pass dynamic file name in app/code/Vendor/Module/web/template/form/element/download.html? – Rutvee Sojitra Nov 13 '18 at 9:11
  • What's the purpose of template and elementTmpl? – Adarsh M Nov 18 '19 at 12:51
  • Where to add the file to download? – Abhilash Acharya Jan 2 '20 at 9:42
  • @RutveeSojitra please check my answer – 26vivek Feb 5 '20 at 10:26

in ui_form.xml

<field name="custom_link" sortOrder="20" formElement="input">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="source" xsi:type="string">custom_test</item>
            <item name="elementTmpl" xsi:type="string">Vendor_Module/input.html</item>
        <label translate="true">Custom Url</label>

note following things:

(custom_link) field ID

(elementTmpl) template path

(my_url) dynamic value will set in Data Provider

in app/code/Vendor/Module/view/adminhtml/web/template/input.html

<a data-bind="attr: {href : value}">My Link</a>

In DataProvider.php

foreach ($items as $item) {
    $this->loadedData[$item->getId()] = $item->getData();
    $this->loadedData[$item->getId()]['my_url'] = "https://my_custom_link.com";

Replace my_custom_link with your link

You can see the output in the screenshot enter image description here

  • Is it possible to bind more than one variable to input.html in DataProvider? – musicliftsme Jan 6 at 4:31
  • @musicliftsme not sure but you can try return array from the data provider and access it as value.property or value[0] – 26vivek Feb 9 at 5:00

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.