I am creating a module for check distance from store to various area. For this, I need to give sample csv file format to store managers so they can format their csv files and upload in admin-side.

I need to put that link besides file-browse button.

For that, I have created below code.

            'name'  => 'csv_file',
            'label' => __('Upload Csv File'),
            'title' => __('Upload Csv File'),
            'note' => '<br><span id="sample-file-span" 
                                    . '<a id="sample-file-link" href="#">'
                                    . __('Download Sample File')
                                    . '</a></span>',

By this, I can see the link.

My questions are,

Where I put my sample csv file in my module ?

What to write code in href attribute so store-manager can download it ?

Advanced Thanks !


1 Answer 1


You need to create custom type in form

$fieldset->addType('csvfile', '\Vendor\Module\Block\Adminhtml\Youblock\Renderer\Csvfile');

        'name'  => 'csvfile',
        'label' => __('csvfile'),
        'title' => __('csvfile'),




namespace Vendor\Module\Block\Adminhtml\Yourblock\Renderer;

use Magento\Framework\DataObject;

class Csvfile extends \Magento\Framework\Data\Form\Element\AbstractElement
    protected $_assetRepo;

    public function __construct( 
         \Magento\Framework\View\Asset\Repository $assetRepo
    ) {
         $this->_assetRepo = $assetRepo;

    public function getElementHtml()
         $csvFile = $this->_assetRepo->getUrl('Vendor_Module::csv/yourfile.csv');
         $csvLink = "<a href=".$csvFile." target='_blank'>Download Sample File</a>";
        return $csvLink;


Copy yourfile.csv at


  • Thank you so much @Prince Patel ! Its working exactly what I want :)
    – Prince
    Commented May 12, 2017 at 10:04
  • @Prince how can I get the value of file element in renderer?
    – Rajan Soni
    Commented Mar 7, 2018 at 12:49
  • @Rajan Soni $this->getValue(); used these get value of element. Commented Jul 14, 2018 at 6:11

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.