3

I am new in Magento and trying to modify an extension. I would like the href to open in a new tab. The code is as follows:

if ($itemRule['file_action'] == \Mageplaza\ProductAttachments\Model\Config\Source\FileAction::VIEWONLINE) {
    $href = $block->getUrl('mpattachments/file/viewonline', ['id' => $itemRule['file_id'], 'product_id' => $block->getProduct()->getId()]);
} else {
    $href = $block->getUrl('mpattachments/file/download', ['id' => $itemRule['file_id'], 'product_id' => $block->getProduct()->getId()]);
}

I Would highly appreciate some help.

  • could you share your whole code for this one – fmsthird Mar 22 at 6:06
0
<?php $PdfName = $block->getProduct()->getName(); ?>

So:

New tab:

<a href="<?php echo $href; ?>" target="_blank"><?php echo $PdfName; ?></a>

Download :

<a href="<?php echo $href; ?>" download="<?php echo $PdfName; ?>"><?php echo $PdfName; ?></a>
  • thank you very much..I will see if that works and let you know.! :-) – ishu Apr 5 at 3:52
0

Actually you need to add attribute target="_blank" in anchor tag in phtml file where this $href is echoing in href tag. You can enable template hints to find which is this template actually.

0

If you are using anchor() tag you can append a target attribute like this:

<a href="<?php echo $href;?>" target="_blank" >View PDF</a>

If you have a button you can try as:

<input type="button" onclick="window.open(<?php echo $href;?>,'_blank')" />

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.