cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 link in a module

SOLVED

Magento 2 link in a module

Hello it's me again

 

I'm a french student and I'm actually trying to learn how to use Magento 2. I'm actually trying  to put 2 pdf in my module that i can open in a certain page but i can't do it, i can only display them by putting them in the media folder but it's not very good for what i have to do can someone explain me how i can use them since my module folder please.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 2 link in a module

@Antoine553

 

Add pdf file in your module,

app/code/{Vendor}/{Modulename}/view/adminthml/web/pdf/custom1.pdf
app/code/{Vendor}/{Modulename}/view/adminhtml/web/pdf/custom2.pdf

 

Then do static content deploy.

 

If works then mark as solution. 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

4 REPLIES 4

Re: Magento 2 link in a module

You can add your pdf in your custom module.

 

Add pdf file in your module,

app/code/{Vendor}/{Modulename}/view/frontend/web/pdf/custom1.pdf
app/code/{Vendor}/{Modulename}/view/frontend/web/pdf/custom2.pdf

now run command for deployment,

 

php bin/magento setup:static-content:deploy

Now you can use your pdf file in any template file like this,

 

$pdf1 = $block->getViewFileUrl('Vendor_Modulename::pdf/custom1.pdf');
<a href="<?php echo $pdf1;?>">pdf1</a>

$pd2 = $block->getViewFileUrl('Vendor_Modulename::pdf/custom2.pdf');
<a href="<?php echo $pdf2;?>">pdf1</a>

Please let me know if you have query.

 

If solutions helpful, click Kudos and Accept as solutions 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Magento 2 link in a module

Thanks for your answer

 

after a try i have an error 404 here is the url link given by the href of the pdf

 

mymagentofile/pub/static/version1499066266/adminhtml/Magento/backend/en_US/Vendor_Modulename/pdf/custom1.pdf

Re: Magento 2 link in a module

@Antoine553

 

Add pdf file in your module,

app/code/{Vendor}/{Modulename}/view/adminthml/web/pdf/custom1.pdf
app/code/{Vendor}/{Modulename}/view/adminhtml/web/pdf/custom2.pdf

 

Then do static content deploy.

 

If works then mark as solution. 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Magento 2 link in a module

It work thanks you very much Sunil and Rakesh